-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
38 lines (30 loc) · 890 Bytes
/
index.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
import Hapi from '@hapi/hapi';
import routes from './dist/routes.js';
// These lines make "require" available.
import { createRequire } from 'module';
const require = createRequire(import.meta.url);
const server = Hapi.server({
port: process.env.PORT || 3000,
});
async function init() {
await server.register(require('@hapi/inert'));
server.validator(require('joi'));
server.route(routes);
await server.start();
console.log('server running ', server.info.uri);
}
init();
async function gracefullyStop() {
console.log('stopping hapi server');
try {
await server.stop({ timeout: 10000 });
console.log('hapi server stopped');
} catch (err) {
console.log(err);
process.exit(1);
}
process.exit(0);
}
// listen on SIGINT and SIGTERM signal and gracefully stop the server.
process.on('SIGINT', gracefullyStop);
process.on('SIGTERM', gracefullyStop);