joyent-portal/packages/portal-api/server.js

60 lines
1012 B
JavaScript
Raw 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',
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,
options: { namespace: 'portal', subsystem: 'api' }
}
2017-06-21 01:02:40 +03:00
],
2017-08-28 23:31:38 +03:00
(err) => {
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-04-28 00:59:03 +03:00
);
function handlerError (error) {
if (error) {
console.error(error);
process.exit(1);
}
}