rsnext/test/integration/custom-server/server.js
Hannes Bornö 2e135346cf
Don't convert error to string (#36804)
Stack trace disappears when error is converted to string.
I changed the types in `log.ts` to match `console.log`/`console.error`/`console.warn`.

fixes #31591
2022-05-11 17:02:15 +00:00

66 lines
1.6 KiB
JavaScript

if (process.env.POLYFILL_FETCH) {
global.fetch = require('node-fetch').default
}
const http = require('http')
const next = require('next')
const dev = process.env.NODE_ENV !== 'production'
const dir = __dirname
const port = process.env.PORT || 3000
const app = next({ dev, dir })
const handleNextRequests = app.getRequestHandler()
app.prepare().then(() => {
const server = new http.Server(async (req, res) => {
if (req.url === '/no-query') {
return app.render(req, res, '/no-query')
}
if (req.url === '/unhandled-rejection') {
Promise.reject(new Error('unhandled rejection'))
return res.end('ok')
}
if (/setAssetPrefix/.test(req.url)) {
app.setAssetPrefix(`http://127.0.0.1:${port}`)
} else if (/setEmptyAssetPrefix/.test(req.url)) {
app.setAssetPrefix(null)
} else {
// This is to support multi-zones support in localhost
// and may be in staging deployments
app.setAssetPrefix('')
}
if (/test-index-hmr/.test(req.url)) {
return app.render(req, res, '/index')
}
if (/dashboard/.test(req.url)) {
return app.render(req, res, '/dashboard')
}
if (/static\/hello\.text/.test(req.url)) {
return app.render(req, res, '/static/hello.text')
}
if (/no-slash/.test(req.url)) {
try {
await app.render(req, res, 'dashboard')
} catch (err) {
res.end(err.message)
}
}
handleNextRequests(req, res)
})
server.listen(port, (err) => {
if (err) {
throw err
}
console.log(`> Ready on http://localhost:${port}`)
})
})