-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
27 lines (24 loc) · 740 Bytes
/
server.js
File metadata and controls
27 lines (24 loc) · 740 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
const {join} = require('path')
const {createServer} = require('http')
const next = require('next')
const app = next({dev: process.env.NODE_ENV !== 'production'})
const handle = app.getRequestHandler()
const port = Number.parseInt(process.argv.pop().split('=')[1] || 9000)
const root = process.cwd()
app.prepare().then(() => {
createServer((req, res) => {
if (req.url.startsWith('/static/')) {
if (req.url.endsWith('/sw.js')) {
res.setHeader('Service-Worker-Allowed', '/')
}
app.serveStatic(req, res, join(root, `.${req.url}`))
} else {
handle(req, res, req.url)
}
}).listen(port, err => {
if (err) {
throw err
}
console.log(`> Ready on http://localhost:${port}`)
})
})