-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
51 lines (46 loc) · 1.22 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
const next = require('next');
const Hapi = require('hapi');
const Good = require('good');
const { defaultHandlerWrapper } = require('./next-wrapper');
const dev = process.env.NODE_ENV !== 'production';
const app = next({ dev });
const server = new Hapi.Server();
const port = process.env.PORT || 3000;
const pluginOptions = [
{
register: Good,
options: {
ops: false,
reporters: {
console: [{
module: 'good-console'
}, 'stdout']
}
}
}
];
app.prepare()
.then(() => {
server.connection({ port });
server.register(pluginOptions)
.then(() => {
server.route({
method: 'GET',
path: '/health',
handler: (request, reply) => {
reply({ status: 'OK' });
}
});
server.route({
method: 'GET',
path: '/{p*}', /* catch all route */
handler: defaultHandlerWrapper(app)
});
server.start().catch(error => {
console.log('Error starting server')
console.log(error)
}).then(() => {
console.log('> Ready on http://localhost:3000')
});
});
});