-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
77 lines (63 loc) · 1.97 KB
/
index.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*jslint node: true */
/*jslint esversion: 6 */
'use strict';
const AuthBearer = require('hapi-auth-bearer-token');
const Hapi = require('hapi');
const Inert = require('inert');
const path = require('path');
const authProvider = require('./server/services/auth/pam-auth-provider');
const env = require('./server/util/environment');
console.info('Using ' + process.cwd() + ' as the present working directory...');
console.info('Using ' + env.current + ' as the current environment...');
var server = new Hapi.Server({
connections: {
routes: {
files: {
relativeTo: path.join(__dirname, '.')
}
}
}
});
server.connection({
port: env.port
});
server.register(Inert);
server.register(AuthBearer, function(error) {
server.auth.strategy('pamToken', 'bearer-access-token', {
validateFunc: function (token, cb) {
authProvider.getTokenValue(token).then(function () {
return cb(null, true, { token: token });
}, function () {
if (error) {
console.error('Authentication failed.');
} else {
console.error('Authentication failed with an error: ' + error);
}
return cb(null, false, { token: token });
});
}
});
});
var routers = [
require('./server/routes/static'),
require('./server/routes/auth'),
require('./server/routes/system'),
require('./server/routes/processor'),
require('./server/routes/memory'),
require('./server/routes/disks'),
require('./server/routes/network'),
require('./server/routes/processes'),
require('./server/routes/bandwidth'),
require('./server/routes/assets')
];
routers.forEach(function (router) {
router.forEach(function (route) {
server.route(route);
});
});
server.start(function(err) {
if (err) {
throw err;
}
console.log('Server running at:', server.info.uri);
});