2018-11-19 15:36:18 +00:00
|
|
|
const http = require('http')
|
2018-02-02 14:43:36 +00: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(() => {
|
2018-11-19 15:36:18 +00:00
|
|
|
const server = new http.Server((req, res) => {
|
2018-12-10 22:40:26 +00:00
|
|
|
if (req.url === '/no-query') {
|
|
|
|
return app.render(req, res, '/no-query')
|
|
|
|
}
|
|
|
|
|
2018-02-02 14:43:36 +00:00
|
|
|
if (/setAssetPrefix/.test(req.url)) {
|
2018-02-02 20:09:24 +00:00
|
|
|
app.setAssetPrefix(`http://127.0.0.1:${port}`)
|
2018-02-03 16:12:01 +00:00
|
|
|
} else if (/setEmptyAssetPrefix/.test(req.url)) {
|
|
|
|
app.setAssetPrefix(null)
|
2018-02-02 14:43:36 +00:00
|
|
|
} else {
|
|
|
|
// This is to support multi-zones support in localhost
|
|
|
|
// and may be in staging deployments
|
|
|
|
app.setAssetPrefix('')
|
|
|
|
}
|
|
|
|
|
|
|
|
handleNextRequests(req, res)
|
|
|
|
})
|
|
|
|
|
|
|
|
server.listen(port, (err) => {
|
|
|
|
if (err) {
|
|
|
|
throw err
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log(`> Ready on http://localhost:${port}`)
|
|
|
|
})
|
|
|
|
})
|