-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
66 lines (53 loc) · 1.27 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
60
61
62
63
64
65
66
const Hapi = require('hapi');
const Cors = require('hapi-cors');
const Path = require('path');
const Hoek = require('hoek');
var ItemStore = require('./lib/itemStore');
// ItemStore.initialize();
const server = new Hapi.Server({
connections: {
routes: {
files: {
relativeTo: Path.join(__dirname, './')
}
}
}
});
server.register(require('inert'), (err) => {
if(err) {
throw err;
}
});
server.register(require('vision'), (err) => {
Hoek.assert(!err, err);
server.views({
engines: {
html: require('handlebars')
},
relativeTo: __dirname,
path: 'templates'
});
});
server.connection({ port: ~~process.env.PORT || 3000 });
// var server = new Hapi.Server(~~process.env.PORT || 3000, '0.0.0.0');
server.register({
register: Cors
}, function(err){
server.start(function(){
console.log(server.info.uri);
});
});
server.ext('onRequest', function(request, reply) {
console.log('Request received' + request.path);
reply.continue();
});
server.ext('onPreResponse', function(request, reply) {
if(request.response.isBoom) {
return reply.view('error', request.response);
}
reply.continue();
});
server.route(require('./lib/routes'));
server.start(function() {
console.log('Listening on ' + server.info.uri);
});