joyent-portal/packages/portal-api/server.js
2017-09-13 14:32:32 -05:00

65 lines
1.0 KiB
JavaScript

'use strict';
const Brule = require('brule');
const Good = require('good');
const Hapi = require('hapi');
const Toppsy = require('toppsy');
const Portal = require('./lib');
const server = new Hapi.Server();
server.connection({
port: 3000,
routes: {
cors: Boolean(process.env.CORS)
}
});
const goodOptions = {
ops: {
interval: 1000
},
reporters: {
consoleReporter: [{
module: 'good-squeeze',
name: 'Squeeze',
args: [{
log: '*',
response: '*',
error: '*'
}]
}, {
module: 'good-console'
}, 'stdout']
}
};
server.register([
Brule,
Portal,
{
register: Good,
options: goodOptions
},
{
register: Toppsy,
options: {
namespace: 'portal',
subsystem: 'api'
}
}
], (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);
}
}