forked from outmoded/hapijs.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
84 lines (66 loc) · 1.86 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
'use strict';
const Config = require('getconfig');
const Hapi = require('hapi');
const Jade = require('jade');
const Markdown = require('./lib/markdown');
const Path = require('path');
if (Config.server.cache) {
Config.server.cache.engine = require(Config.server.cache.engine);
}
const server = new Hapi.Server(Config.server);
Jade.filters.markdown = Markdown.parseSync;
server.connection({
host: Config.host,
port: Config.port
});
server.ext('onPreResponse', (request, reply) => {
if (!request.response.isBoom) {
return reply.continue();
}
return reply.view('error', request.response).code(request.response.output.statusCode);
});
server.method(require('./lib/npm').methods);
server.method(require('./lib/github').methods);
server.method(require('./lib/markdown').methods);
server.method(require('./lib/community').methods);
server.method(require('./lib/changelog').methods);
const plugins = [
{
register: require('good'),
options: {
ops: {
interval: 30 * 1000
},
reporters: {
console: [{
module: 'good-console',
args: [{ log: '*', response: '*', log: '*' }]
}, 'stdout']
}
}
},
require('vision'),
require('inert')
];
if (Config.getconfig.env === 'dev') {
plugins.push(require('building-static-server'));
}
server.register(plugins, (err) => {
if (err) {
throw err;
}
server.views({
engines: {
jade: Jade
},
path: Path.join(__dirname, 'templates'),
isCached: Config.getconfig.env === 'production'
});
server.route(require('./lib/routes').routes);
server.start((err) => {
if (err) {
throw err;
}
console.log('hapijs.com running at: ' + server.info.uri);
});
});