-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathapp.js
executable file
·53 lines (42 loc) · 1.58 KB
/
app.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
52
/**
* Created by uzysjung on 17. 12. 13..
*/
'use strict';
const Hapi = require('hapi');
const config = require('./config');
const server = new Hapi.Server({ port: config.port, routes: { cors: true , jsonp: 'callback' } });
const main = async () => {
try {
await Promise.all([ require('./src/plugins/inert')(server), require('./src/plugins/vision')(server)]);
await require('./src/plugins/scooter')(server);
await require('./src/plugins/bassmaster')(server);
await require('./src/plugins/h2o2')(server);
await require('./src/plugins/therealyou')(server);
await require('./src/plugins/hapi-auth-basic')(server);
await require('./src/plugins/hapi-swagger')(server);
server.route(require('./src/routes/default'));
//for static file but not recommend due to performance , use nginx.
server.route({ method: 'GET', path: '/public/{path*}', handler: { directory: { path: './public' ,redirectToSlash: true } } });
await server.start();
console.log(['info', 'server'], 'Server environment: ' + config.type);
console.log(['info', 'server'], 'Server running at: ' + server.info.uri);
} catch (e) {
console.error(['error', 'server'],'Server Error Occured' + e);
console.error('stack - ',e.stack);
}
return server;
};
main();
process.on('SIGINT', async () => {
try {
if(config.type !=='development') {
console.log('Gaia Hapi stoppping Hapi');
await server.stop({ timeout:1000 });
}
} catch(e) {
console.error(e);
}
console.log('Gaia Hapi stopped');
return process.exit(0);
});
module.exports = exports = server;