-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
38 lines (35 loc) · 1.25 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
var Hapi = require('hapi');
var config = require('getconfig');
var server = new Hapi.Server(config.http.listen, config.http.port);
var moonbootsConfig = require('./moonbootsConfig');
var fakeApi = require('./fakeApi');
var internals = {};
// set clientconfig cookie
internals.configStateConfig = {
encoding: 'none',
ttl: 1000 * 60 * 15,
isSecure: config.isSecure
};
server.state('config', internals.configStateConfig);
internals.clientConfig = JSON.stringify(config.client);
server.ext('onPreResponse', function(request, reply) {
if (!request.state.config) {
var response = request.response;
return reply(response.state('config', encodeURIComponent(internals.clientConfig)));
}
else {
return reply();
}
});
// require moonboots_hapi plugin
server.pack.register({plugin: require('moonboots_hapi'), options: moonbootsConfig}, function (err) {
if (err) throw err;
server.pack.register(fakeApi, function (err) {
if (err) throw err;
// If everything loaded correctly, start the server:
server.start(function (err) {
if (err) throw err;
console.log('COINSCollector is running at: http://localhost:' + config.http.port + ' Yep. That\'s pretty awesome.');
});
});
});