forked from gitpod-samples/NextSimpleStarter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
25 lines (20 loc) · 625 Bytes
/
server.js
File metadata and controls
25 lines (20 loc) · 625 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
const { createServer } = require('http')
const path = require('path')
const next = require('next')
const dev = process.env.NODE_ENV !== 'production'
const app = next({ dir: '.', dev })
const handle = app.getRequestHandler()
const PORT = process.env.PORT || 3000
app.prepare().then(_ => {
const server = createServer((req, res) => {
if (req.url === '/sw.js' || req.url.startsWith('/precache-manifest')) {
app.serveStatic(req, res, path.join(__dirname, '.next', req.url))
} else {
handle(req, res)
}
})
server.listen(PORT, err => {
if (err) throw err
console.log(`> App running on port ${PORT}`)
})
})