2014-08-27 02:51:57 +04:00
|
|
|
var settings = require('./settings');
|
2014-08-06 07:35:25 +04:00
|
|
|
|
2014-12-11 02:16:36 +03:00
|
|
|
var Hapi = require('hapi');
|
|
|
|
var routes = require('./api/routes');
|
2014-08-06 07:35:25 +04:00
|
|
|
|
|
|
|
|
2015-01-03 03:40:11 +03:00
|
|
|
var server = module.exports = new Hapi.Server();
|
2014-12-23 02:52:42 +03:00
|
|
|
server.connection({
|
|
|
|
host: settings.HOST,
|
|
|
|
port: settings.PORT,
|
|
|
|
routes: {
|
|
|
|
validate: {
|
|
|
|
options: {
|
|
|
|
abortEarly: false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2015-01-03 03:40:11 +03:00
|
|
|
|
2014-12-11 02:16:36 +03:00
|
|
|
routes(server);
|
2014-08-06 07:35:25 +04:00
|
|
|
|
2015-01-03 03:40:11 +03: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);
|
|
|
|
});
|
|
|
|
}
|
2014-12-17 05:20:29 +03:00
|
|
|
|
|
|
|
server.register({
|
2014-12-17 09:28:59 +03:00
|
|
|
register: require('hapi-node-postgres'),
|
2014-12-17 05:20:29 +03:00
|
|
|
options: {
|
|
|
|
connectionString: settings.POSTGRES_URL
|
|
|
|
}
|
|
|
|
}, function (err) {
|
|
|
|
if (err) {
|
2014-12-17 09:28:59 +03:00
|
|
|
console.error('Failed to load "hapi-node-postgres" plugin: %s', err);
|
2014-12-17 05:20:29 +03:00
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
});
|