galaxy-api/index.js

65 строки
1.2 KiB
JavaScript
Исходник Постоянная ссылка Обычный вид История

'use strict';
2014-12-11 02:16:36 +03:00
var Hapi = require('hapi');
2015-01-14 19:02:40 +03:00
// Polyfill for ES6's Promises, replaces the global namespace Promise object.
require('es6-promise').polyfill();
var db = require('./lib/db');
2014-12-11 02:16:36 +03:00
var routes = require('./api/routes');
var settings = require('./settings');
2014-08-06 07:35:25 +04:00
var server = module.exports = new Hapi.Server();
server.connection({
host: settings.HOST,
port: settings.PORT,
routes: {
validate: {
options: {
abortEarly: false
}
}
}
});
server.route(routes);
2014-08-06 07:35:25 +04:00
// Do not start the server when this script is required by another script.
if (!module.parent) {
server.start(function () {
console.log('Listening on %s', server.info.uri);
});
}
var pgPlugin = {
register: function (server, options, next) {
db.connect(options.connectionString);
server.on('stop', function () {
db.disconnect();
});
next();
}
};
pgPlugin.register.attributes = {
name: 'pgPlugin',
version: '1.0.0'
};
server.register({
register: pgPlugin,
options: {
connectionString: settings.POSTGRES_URL
}
}, function (err) {
if (err) {
console.error('Failed to load "pgPlugin" plugin: %s', err);
throw err;
}
});