2017-11-27 14:08:18 +00:00
|
|
|
var express = require('express');
|
|
|
|
var app = module.exports = express();
|
|
|
|
var bodyParser = require('body-parser');
|
|
|
|
var config = require('../application/config.js');
|
|
|
|
var database = require('../application/database.js');
|
|
|
|
|
|
|
|
// Body parser middleware
|
|
|
|
app.use(bodyParser.json());
|
|
|
|
app.use(bodyParser.urlencoded({extended: true}));
|
|
|
|
|
|
|
|
// Load routes
|
2017-12-26 09:02:47 +00:00
|
|
|
app.use('/', require('../application/router.js'));
|
2017-11-27 14:08:18 +00:00
|
|
|
|
2018-02-03 19:14:44 +00:00
|
|
|
app.start = function(port) {
|
|
|
|
var listener = app.listen(port ? port : config.app.port, function() {
|
2017-11-27 14:08:18 +00:00
|
|
|
var servicePath = 'http://' + listener.address().address + ':' + listener.address().port;
|
|
|
|
database.init();
|
|
|
|
|
|
|
|
let packageJson = require('../package.json');
|
|
|
|
console.log(`Web server ${packageJson.name} listening at: ${servicePath}`);
|
|
|
|
|
|
|
|
if (config.app.debug) {
|
|
|
|
console.log(`${packageJson.name} service debug mode enabled`);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return listener;
|
|
|
|
};
|
|
|
|
|
|
|
|
if (require.main === module) {
|
|
|
|
app.start();
|
|
|
|
}
|