1 | 'use strict';
|
2 | const debug = require('debug')('alexia:debug');
|
3 | const info = require('debug')('alexia:info');
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | module.exports = (app, options) => {
|
14 | const Hapi = require('hapi');
|
15 | const server = new Hapi.Server();
|
16 |
|
17 | options = Object.assign({}, options);
|
18 |
|
19 | server.connection({
|
20 | port: options.port || process.env.PORT || 8888
|
21 | });
|
22 |
|
23 | server.route({
|
24 | path: options.path || '/',
|
25 | method: 'POST',
|
26 | handler: (request, response) => {
|
27 | app.handle(request.payload, (data) => {
|
28 | response(data);
|
29 | });
|
30 | }
|
31 | });
|
32 |
|
33 | info(`Server created on URI: "${server.info.uri}"`);
|
34 | debug(`Server created on URI: "${server.info.uri}"`);
|
35 | return server;
|
36 | };
|