-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
33 lines (27 loc) · 878 Bytes
/
server.js
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
28
29
30
31
32
33
const dev = process.env.NODE_ENV !== 'production'
if (dev) {
require('dotenv').config()
}
const next = require('next')
const routes = require('./routes')
const app = next({ dev })
const handler = routes.getRequestHandler(app)
const port = parseInt(process.env.PORT, 10) || 3000
const express = require('express')
const { join } = require('path')
app.prepare().then(() => {
const server = express()
server.get('/service-worker.js', (req, res) => {
const filePath = join(__dirname, '.next', 'service-worker.js')
return app.serveStatic(req, res, filePath)
})
server.get('/sitemap.xml', (req, res) => {
const filePath = join(__dirname, 'static', 'sitemap.xml')
return app.serveStatic(req, res, filePath)
})
server.use(handler)
server.listen(port, (err) => {
if (err) throw err
console.log(`> Ready on http://localhost:${port}`)
})
})