Created
February 13, 2019 09:12
-
-
Save timneutkens/432f5278010bce0cb92d97979fa6a76f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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