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

61 lines
1.0 KiB
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 Pack = require('./package');
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-04-28 00:59:03 +03:00
(err) => {
handlerError(err);
server.start((err) => {
handlerError(err);
console.log(`server started at http://localhost:${server.info.port}`);
});
}
);
function handlerError (error) {
if (error) {
console.error(error);
process.exit(1);
}
}