1
0
mirror of https://github.com/yldio/copilot.git synced 2024-12-01 07:30:07 +02:00
copilot/packages/portal-api/server.js
geek 6cd39b2d8c build: extended support for containerpilot v3
with sensors and local-compose
2017-06-20 13:54:37 +01:00

61 lines
1.0 KiB
JavaScript

'use strict';
const Brule = require('brule');
const Hapi = require('hapi');
const Inert = require('inert');
const Vision = require('vision');
const HapiSwagger = require('hapi-swagger');
const Pack = require('./package');
const Portal = require('./lib');
const server = new Hapi.Server();
server.connection({
port: 3000,
routes: {
cors: true
}
});
const swaggerOptions = {
info: {
'title': 'Portal API Documentation',
'version': Pack.version
}
};
const portalOptions = {
data: {
db: {
host: process.env.RETHINK_HOST || 'localhost'
}
}
};
server.register([
Brule,
Inert,
Vision,
{
register: Portal,
options: portalOptions
},
{
register: HapiSwagger,
options: swaggerOptions
}],
(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);
}
}