-
Notifications
You must be signed in to change notification settings - Fork 3
/
server.js
47 lines (42 loc) · 1.2 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
const H2o2 = require('@hapi/h2o2');
const Hapi = require('@hapi/hapi');
const Inert = require('@hapi/inert');
const Joi = require('joi');
const Vision = require('@hapi/vision');
const routes = require('./routes');
const auth = require('./auth');
module.exports = async (elastic, config, cb) => {
const server = new Hapi.Server({ port: config.port, routes: { cors: { origin: 'ignore' }, log: { collect: true } } });
server.validator(Joi);
server.route(routes(elastic, config));
if (config.auth) {
server.route(auth());
await server.register(require('hapi-auth-jwt2'));
await server.register(require('./auth/authentication'));
}
try {
await server.register([
Inert,
Vision,
H2o2,
{
plugin: require('./routes/plugins/error'),
options: {
config
}
}
]);
} catch (err) {
return cb(err);
}
server.views({
engines: { html: { module: require('handlebars'), compileMode: 'sync' } },
relativeTo: __dirname,
path: './templates/pages',
layout: 'default',
layoutPath: './templates/layouts',
partialsPath: './templates/partials',
helpersPath: './templates/helpers'
});
cb(null, { server, elastic });
};