This repository has been archived by the owner on Jul 31, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 268
/
server.js
82 lines (69 loc) · 2.13 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
'use strict';
const Config = require('getconfig');
const Hapi = require('hapi');
const Pug = require('pug');
const Markdown = require('./lib/markdown');
const Path = require('path');
require('./lib/cron');
const isProd = process.env.NODE_ENV === 'production';
if (Config.server.cache && isProd) {
Config.server.cache.engine = require(Config.server.cache.engine);
}
const server = Hapi.server(Config.server);
Pug.filters.markdown = Markdown.parseSync;
const start = async function () {
server.ext({
type: 'onPreResponse',
method: function (request, h) {
if (!request.response.isBoom) {
return h.continue;
}
return h.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/changelog').methods);
const plugins = [
{
plugin: 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'));
}
await server.register(plugins);
server.views({
engines: {
pug: Pug
},
path: Path.join(__dirname, 'templates'),
isCached: Config.getconfig.env === 'production'
});
server.route(require('./lib/routes')(server));
try {
await server.start();
console.log('hapijs.com running at: ' + server.info.uri);
}
catch (err) {
console.error(err);
process.exit(1);
}
};
process.on('unhandledRejection', (reason, p) => {
console.log('Unhandled Rejection at:', p, 'reason:', reason);
});
start();