2018-11-19 16:36:18 +01:00
|
|
|
const http = require('http')
|
2018-02-02 15:43:36 +01:00
|
|
|
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(() => {
|
2020-04-06 18:54:42 +02:00
|
|
|
const server = new http.Server(async (req, res) => {
|
2018-12-10 23:40:26 +01:00
|
|
|
if (req.url === '/no-query') {
|
|
|
|
return app.render(req, res, '/no-query')
|
|
|
|
}
|
|
|
|
|
2018-02-02 15:43:36 +01:00
|
|
|
if (/setAssetPrefix/.test(req.url)) {
|
2018-02-02 21:09:24 +01:00
|
|
|
app.setAssetPrefix(`http://127.0.0.1:${port}`)
|
2018-02-03 17:12:01 +01:00
|
|
|
} else if (/setEmptyAssetPrefix/.test(req.url)) {
|
|
|
|
app.setAssetPrefix(null)
|
2018-02-02 15:43:36 +01:00
|
|
|
} else {
|
|
|
|
// This is to support multi-zones support in localhost
|
|
|
|
// and may be in staging deployments
|
|
|
|
app.setAssetPrefix('')
|
|
|
|
}
|
|
|
|
|
2019-03-12 12:40:49 +01:00
|
|
|
if (/test-index-hmr/.test(req.url)) {
|
|
|
|
return app.render(req, res, '/index')
|
|
|
|
}
|
|
|
|
|
2019-04-18 05:15:56 +02:00
|
|
|
if (/dashboard/.test(req.url)) {
|
|
|
|
return app.render(req, res, '/dashboard/index')
|
|
|
|
}
|
|
|
|
|
2019-11-13 04:52:58 +01:00
|
|
|
if (/static\/hello\.text/.test(req.url)) {
|
|
|
|
return app.render(req, res, '/static/hello.text')
|
|
|
|
}
|
|
|
|
|
2020-04-06 18:54:42 +02:00
|
|
|
if (/no-slash/.test(req.url)) {
|
|
|
|
try {
|
|
|
|
await app.render(req, res, 'dashboard')
|
|
|
|
} catch (err) {
|
|
|
|
res.end(err.message)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-02 15:43:36 +01:00
|
|
|
handleNextRequests(req, res)
|
|
|
|
})
|
|
|
|
|
2019-05-30 03:19:32 +02:00
|
|
|
server.listen(port, err => {
|
2018-02-02 15:43:36 +01:00
|
|
|
if (err) {
|
|
|
|
throw err
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log(`> Ready on http://localhost:${port}`)
|
|
|
|
})
|
|
|
|
})
|