2017-04-28 00:59:03 +03:00
|
|
|
'use strict';
|
|
|
|
|
2017-06-20 02:52:20 +03:00
|
|
|
const Brule = require('brule');
|
2017-04-28 00:59:03 +03:00
|
|
|
const Hapi = require('hapi');
|
2017-06-21 00:11:47 +03:00
|
|
|
const HapiSwagger = require('hapi-swagger');
|
2017-04-28 00:59:03 +03:00
|
|
|
const Inert = require('inert');
|
2017-06-21 00:11:47 +03:00
|
|
|
const Toppsy = require('toppsy');
|
2017-04-28 00:59:03 +03:00
|
|
|
const Vision = require('vision');
|
|
|
|
const Pack = require('./package');
|
|
|
|
const Portal = require('./lib');
|
|
|
|
|
|
|
|
const server = new Hapi.Server();
|
2017-06-05 20:14:32 +03:00
|
|
|
server.connection({
|
|
|
|
port: 3000,
|
|
|
|
routes: {
|
|
|
|
cors: true
|
|
|
|
}
|
|
|
|
});
|
2017-04-28 00:59:03 +03:00
|
|
|
|
2017-06-19 17:37:38 +03:00
|
|
|
const swaggerOptions = {
|
2017-04-28 00:59:03 +03:00
|
|
|
info: {
|
|
|
|
'title': 'Portal API Documentation',
|
|
|
|
'version': Pack.version
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-06-19 17:37:38 +03:00
|
|
|
const portalOptions = {
|
|
|
|
data: {
|
|
|
|
db: {
|
|
|
|
host: process.env.RETHINK_HOST || 'localhost'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-04-28 00:59:03 +03:00
|
|
|
server.register([
|
2017-06-20 02:52:20 +03:00
|
|
|
Brule,
|
2017-04-28 00:59:03 +03:00
|
|
|
Inert,
|
|
|
|
Vision,
|
2017-06-19 17:37:38 +03:00
|
|
|
{
|
|
|
|
register: Portal,
|
|
|
|
options: portalOptions
|
|
|
|
},
|
2017-04-28 00:59:03 +03:00
|
|
|
{
|
|
|
|
register: HapiSwagger,
|
2017-06-19 17:37:38 +03:00
|
|
|
options: swaggerOptions
|
2017-06-21 00:11:47 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
register: Toppsy,
|
|
|
|
options: { namespace: 'portal', subsystem: 'api' }
|
|
|
|
}
|
|
|
|
],
|
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);
|
|
|
|
}
|
|
|
|
}
|