forked from map-egypt/api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
58 lines (53 loc) · 1.26 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
const Hapi = require('hapi');
const server = new Hapi.Server({
connections: {
routes: {
cors: {
origin: ['*'],
additionalHeaders: ['x-requested-with', 'accept-language']
},
payload: { maxBytes: 100485760, timeout: false }
}
}
});
server.connection({port: process.env.PORT});
server.register(require('inert'));
server.route([
{
config: {
auth: false
},
method: 'GET',
path: '/uploaded/{param*}',
handler: {
directory: {
path: './uploaded/',
redirectToSlash: true
}
}
}
]);
server.register(require('hapi-auth-jwt2'), function (err) {
if (err) console.error(err);
server.auth.strategy('jwt', 'jwt', {
key: new Buffer(process.env.AUTH0_SECRET, 'base64'),
validateFunc: function (decoded, request, callback) {
callback(null, true);
},
verifyOptions: {
algorithms: ['HS256'],
audience: process.env.AUTH0_CLIENT_ID
}
});
server.auth.default('jwt');
server.register({
register: require('hapi-router'),
options: {
cwd: __dirname,
routes: './routes/**/*.js'
}
}, function (err) {
if (err) console.error(err);
});
});
module.exports = server;