forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
54 lines (47 loc) · 1.11 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
51
52
53
54
const next = require('next')
const Hapi = require('@hapi/hapi')
const {
pathWrapper,
defaultHandlerWrapper,
nextHandlerWrapper,
} = require('./next-wrapper')
const port = parseInt(process.env.PORT, 10) || 3000
const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev })
const server = new Hapi.Server({
port,
})
app.prepare().then(async () => {
server.route({
method: 'GET',
path: '/a',
handler: pathWrapper(app, '/a'),
})
server.route({
method: 'GET',
path: '/b',
handler: pathWrapper(app, '/b'),
})
server.route({
method: 'GET',
path: '/_next/{p*}' /* next specific routes */,
handler: nextHandlerWrapper(app),
})
server.route({
method: 'GET',
path: '/static/{p*}' /* use next to handle static files */,
handler: nextHandlerWrapper(app),
})
server.route({
method: '*',
path: '/{p*}' /* catch all route */,
handler: defaultHandlerWrapper(app),
})
try {
await server.start()
console.log(`> Ready on http://localhost:${port}`)
} catch (error) {
console.log('Error starting server')
console.log(error)
}
})