-
Notifications
You must be signed in to change notification settings - Fork 0
/
service.ts
47 lines (38 loc) · 1013 Bytes
/
service.ts
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
import * as dotenv from 'dotenv';
dotenv.config();
import {server} from '@hapi/hapi';
import {plugin as HapiPostgres} from './hapi-plugins/hapi-postgres';
import {routes as transactionRoutes} from './api/transaction/routes';
import {routes as walletRoutes} from './api/wallet/routes';
export const service = server({
port: 3000,
host: '0.0.0.0',
});
// healthcheck route
service.route({
method: 'GET',
path: '/',
handler: () => {
return 'Ok';
},
});
service.route(transactionRoutes);
service.route(walletRoutes);
let stopping = false;
export const init = async () => {
await service.register([HapiPostgres]);
await service.initialize();
};
export const start = async () => {
await service.register([HapiPostgres]);
await service.start();
console.log('Server running on %s', service.info.uri);
};
export const stop = async () => {
if (!stopping) {
console.log('Stopping server...');
stopping = true;
await service.stop();
console.log('Server stopped.');
}
};