-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
53 lines (46 loc) · 1.05 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
const Path = require('path');
const Hapi = require('hapi');
const Blipp = require('blipp');
const Boom = require('boom');
const Publisher = require('./publisher');
const nuxtConfig = require('./nuxt.config.js');
const server = new Hapi.Server();
server.connection({
host: '0.0.0.0',
port: 3000,
router: {
stripTrailingSlash: true,
},
routes: { cors: true },
});
server.route([
{
method: ['POST'],
path: '/v1/publish',
config: {
tags: ['api'],
async handler(request, reply) {
try {
const response = await Publisher(request, reply);
reply({ status: 'ok', msg: response });
} catch (err) {
console.error(err);
reply(Boom.badRequest(err));
}
},
},
},
]);
server.register([Blipp], async regErr => {
server.start(srverr => {
if (srverr) {
throw srverr;
} else {
console.log(
`Server ${process.env.NODE_ENV === 'production' ? '(Production)' : '(Dev)'} running at: ${
server.info.uri
}`
);
}
});
});