1
0
mirror of https://github.com/yldio/copilot.git synced 2024-11-28 14:10:04 +02:00
copilot/packages/portal-api/server.js

65 lines
1.0 KiB
JavaScript
Raw Permalink Normal View History

2017-04-28 00:59:03 +03:00
'use strict';
const Brule = require('brule');
const Good = require('good');
2017-04-28 00:59:03 +03:00
const Hapi = require('hapi');
const Toppsy = require('toppsy');
2017-04-28 00:59:03 +03:00
const Portal = require('./lib');
const server = new Hapi.Server();
server.connection({
port: 3000,
routes: {
cors: Boolean(process.env.CORS)
}
});
2017-04-28 00:59:03 +03:00
const goodOptions = {
ops: {
2017-06-22 12:57:03 +03:00
interval: 1000
},
reporters: {
consoleReporter: [{
module: 'good-squeeze',
name: 'Squeeze',
2017-09-13 22:32:32 +03:00
args: [{
log: '*',
response: '*',
error: '*'
}]
}, {
module: 'good-console'
}, 'stdout']
}
};
2017-04-28 00:59:03 +03:00
server.register([
Brule,
Portal,
{
register: Good,
options: goodOptions
},
{
register: Toppsy,
2017-09-13 22:32:32 +03:00
options: {
namespace: 'portal',
subsystem: 'api'
}
}
2017-09-13 22:32:32 +03:00
], (err) => {
2017-08-28 23:31:38 +03:00
handlerError(err);
server.start((err) => {
2017-04-28 00:59:03 +03:00
handlerError(err);
2017-08-28 23:31:38 +03:00
console.log(`server started at http://localhost:${server.info.port}`);
});
2017-09-13 22:32:32 +03:00
});
2017-04-28 00:59:03 +03:00
function handlerError (error) {
if (error) {
console.error(error);
process.exit(1);
}
}