2017-01-10 02:35:10 +00:00
|
|
|
const next = require('next')
|
|
|
|
const Hapi = require('hapi')
|
2017-12-05 18:42:57 +00:00
|
|
|
const { pathWrapper, defaultHandlerWrapper, nextHandlerWrapper } = require('./next-wrapper')
|
2017-01-10 02:35:10 +00:00
|
|
|
|
2017-08-10 18:15:46 +00:00
|
|
|
const port = parseInt(process.env.PORT, 10) || 3000
|
2017-01-10 02:35:10 +00:00
|
|
|
const dev = process.env.NODE_ENV !== 'production'
|
|
|
|
const app = next({ dev })
|
2017-12-05 18:42:57 +00:00
|
|
|
const server = new Hapi.Server({
|
|
|
|
port
|
|
|
|
})
|
2017-02-13 02:12:32 +00:00
|
|
|
|
2017-12-05 18:42:57 +00:00
|
|
|
app
|
|
|
|
.prepare()
|
|
|
|
.then(async () => {
|
|
|
|
server.route({
|
|
|
|
method: 'GET',
|
|
|
|
path: '/a',
|
|
|
|
handler: pathWrapper(app, '/a')
|
|
|
|
})
|
2017-01-10 02:35:10 +00:00
|
|
|
|
2017-12-05 18:42:57 +00:00
|
|
|
server.route({
|
|
|
|
method: 'GET',
|
|
|
|
path: '/b',
|
|
|
|
handler: pathWrapper(app, '/b')
|
|
|
|
})
|
2017-01-10 02:35:10 +00:00
|
|
|
|
2017-12-05 18:42:57 +00:00
|
|
|
server.route({
|
|
|
|
method: 'GET',
|
|
|
|
path: '/_next/{p*}', /* next specific routes */
|
|
|
|
handler: nextHandlerWrapper(app)
|
|
|
|
})
|
2017-01-10 02:35:10 +00:00
|
|
|
|
2017-12-05 18:42:57 +00:00
|
|
|
server.route({
|
|
|
|
method: 'GET',
|
|
|
|
path: '/{p*}', /* catch all route */
|
|
|
|
handler: defaultHandlerWrapper(app)
|
2017-01-10 02:35:10 +00:00
|
|
|
})
|
2017-12-05 18:42:57 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
await server.start()
|
|
|
|
console.log(`> Ready on http://localhost:${port}`)
|
|
|
|
} catch (error) {
|
|
|
|
console.log('Error starting server')
|
|
|
|
console.log(error)
|
|
|
|
}
|
2017-01-10 02:35:10 +00:00
|
|
|
})
|