-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
32 lines (31 loc) · 974 Bytes
/
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
const hapi = require('hapi');
const router = require('./routes/router.js');
const SessionHelper = require('./database/SessionHelper.js');
const hapiAuthJWT = require('hapi-auth-jwt2'); // http://git.io/vT5dZ
const assert = require('assert');
const JWT = require('jsonwebtoken'); // used to sign our content
const inert = require('inert');
require('env2')('.env');
const server = new hapi.Server();
server.connection({
routes: {
cors: {
origin: ['*']
}
},
port: process.env.PORT || 3000
});
server.register([hapiAuthJWT, inert], (err) => {
assert(!err); // halt if error
// see: http://hapijs.com/api#serverauthschemename-scheme
server.auth.strategy('jwt', 'jwt', true, {
key: process.env.JWT_SECRET,
validateFunc: SessionHelper.validate,
verifyOptions: {
ignoreExpiration: true,
algorithms: ['HS256']
}
})
server.route(router);
});
module.exports = server;