-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
59 lines (47 loc) · 1.55 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
52
53
54
55
56
57
58
59
// Require babel
require('babel-register');
require('./config/config').default('server');
const Hapi = require('hapi');
const mailServer = require('./mailServer').MailServer;
const mongoose = require('./util/mongoose').default(process.env.MONGOOSEURI);
const options = require('./config/options').default;
// Create a server with a host and port
const server = new Hapi.Server({
port: process.env.PORT
});
// Start mailServer
server.app.mailServer = new mailServer();
server.app.mailServer.run();
server.app.db = mongoose;
// Create new JWT secret
process.env.JWTSECRET = require('crypto').randomBytes(256).toString('base64');
async function startServer() {
await server.register([
require('inert'),
require('hapi-auth-jwt2'),
require('scooter'),
options.hapiRoutes(__dirname),
options.good
]);
server.auth.strategy('jwt', 'jwt', {
key: process.env.JWTSECRET,
validate: require('./util/auth').validateJWT,
verifyOptions: {algorithms: ['HS256']}
});
await server.start();
process.on('SIGTERM', () => {
server.app.mailServer.stop();
server.stop();
});
require('ascii-art').font('Node', 'Doom', 'red').font('HISP', 'Doom', 'italic+green', ascii => {
console.log(ascii);
console.log('*****');
console.log('API SERVER');
console.log(`${require('date-and-time').format(new Date(), 'HH:mm:ss | DD MMM Y')}`);
console.log(`${server.info.uri}`);
console.log(`NODE_ENV: ${process.env.NODE_ENV}`);
console.log('*****');
});
}
startServer();
module.exports = server;