Skip to content

Instantly share code, notes, and snippets.

@timneutkens
Created February 13, 2019 09:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timneutkens/432f5278010bce0cb92d97979fa6a76f to your computer and use it in GitHub Desktop.
Save timneutkens/432f5278010bce0cb92d97979fa6a76f to your computer and use it in GitHub Desktop.
const TOP_PATHS = new Set(
readdirSync(join(__dirname, '..', 'pages'))
.map(f => f.replace(/\.js$/, ''))
.concat(['', 'static', '_next'])
)
function topRoutesMiddleware(req, res, goNext) {
const topPath = req.path.split('/', 2)[1]
if (TOP_PATHS.has(topPath)) {
const { path: pathname, query } = req
handle(req, res, { pathname, query })
return
}
goNext()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment