-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
50 lines (43 loc) · 1.02 KB
/
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/* eslint-disable no-console */
import express from 'express'
import next from 'next'
import logger from 'morgan'
import router from './server/router/router'
const port = parseInt(process.env.PORT, 10) || 80
const env = process.env.NODE_ENV
const dev = env !== 'production'
const app = next({
dir: '.', // base directory where everything is, could move to src later
dev,
})
const handle = app.getRequestHandler()
let server
app
.prepare()
.then(() => {
server = express()
// Logs
server.use(logger("dev"))
// Router
router(server, handle)
//
server.use(express.json())
server.use(
express.urlencoded({
extended: false,
}),
)
server.listen(port, (err) => {
if (err) {
throw err
}
console.log(`
> Ready on port ${port} [${env}]
http://localhost:80
`)
})
})
.catch((err) => {
console.log('An error occurred, unable to start the server')
console.log(err)
})