rsnext/test/integration/root-optional-revalidate/server.js
JJ Kasper 450742274a
Fix optional catch-all /index revalidate params (#16451)
This corrects the case where `/index` is used during revalidation for an optional catch-all route and `index` is passed as a param even though it should be undefined. This also adds test cases to make sure the params are normalized correctly

Fixes: https://github.com/vercel/next.js/issues/16366
2020-08-21 18:13:24 +00:00

27 lines
664 B
JavaScript

const path = require('path')
const http = require('http')
const server = http.createServer(async (req, res) => {
const render = async (page) => {
const mod = require(`./${path.join('.next/serverless/pages/', page)}`)
try {
return await (mod.render || mod.default || mod)(req, res)
} catch (err) {
res.statusCode = 500
return res.end('internal error')
}
}
try {
await render('/[[...slug]].js')
} catch (err) {
console.error('failed to render', err)
res.statusCode = 500
res.end('Internal Error')
}
})
const port = process.env.PORT || 3000
server.listen(port, () => {
console.log('ready on', port)
})