2017-01-10 02:35:10 +00:00
|
|
|
const next = require('next')
|
|
|
|
const Hapi = require('hapi')
|
2017-02-13 02:12:32 +00:00
|
|
|
const Good = require('good')
|
2017-01-10 02:35:10 +00:00
|
|
|
const { pathWrapper, defaultHandlerWrapper } = require('./next-wrapper')
|
|
|
|
|
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 })
|
|
|
|
const server = new Hapi.Server()
|
|
|
|
|
2017-02-13 02:12:32 +00:00
|
|
|
// add request logging (optional)
|
|
|
|
const pluginOptions = [
|
|
|
|
{
|
|
|
|
register: Good,
|
|
|
|
options: {
|
|
|
|
reporters: {
|
|
|
|
console: [{
|
|
|
|
module: 'good-console'
|
|
|
|
}, 'stdout']
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
2017-01-10 02:35:10 +00:00
|
|
|
app.prepare()
|
|
|
|
.then(() => {
|
2017-08-10 18:15:46 +00:00
|
|
|
server.connection({ port })
|
2017-02-13 02:12:32 +00:00
|
|
|
server.register(pluginOptions)
|
|
|
|
.then(() => {
|
|
|
|
server.route({
|
|
|
|
method: 'GET',
|
|
|
|
path: '/a',
|
|
|
|
handler: pathWrapper(app, '/a')
|
|
|
|
})
|
2017-01-10 02:35:10 +00:00
|
|
|
|
2017-02-13 02:12:32 +00:00
|
|
|
server.route({
|
|
|
|
method: 'GET',
|
|
|
|
path: '/b',
|
|
|
|
handler: pathWrapper(app, '/b')
|
|
|
|
})
|
2017-01-10 02:35:10 +00:00
|
|
|
|
2017-02-13 02:12:32 +00:00
|
|
|
server.route({
|
|
|
|
method: 'GET',
|
|
|
|
path: '/{p*}', /* catch all route */
|
|
|
|
handler: defaultHandlerWrapper(app)
|
|
|
|
})
|
2017-01-10 02:35:10 +00:00
|
|
|
|
2017-02-13 02:12:32 +00:00
|
|
|
server.start().catch(error => {
|
|
|
|
console.log('Error starting server')
|
|
|
|
console.log(error)
|
|
|
|
}).then(() => {
|
2017-08-10 18:15:46 +00:00
|
|
|
console.log(`> Ready on http://localhost:${port}`)
|
2017-02-13 02:12:32 +00:00
|
|
|
})
|
2017-01-10 02:35:10 +00:00
|
|
|
})
|
|
|
|
})
|