2017-05-30 06:06:14 +00:00
|
|
|
var express = require('express');
|
2017-05-30 06:50:16 +00:00
|
|
|
var app = module.exports = express();
|
2017-05-30 06:06:14 +00:00
|
|
|
var bodyParser = require('body-parser');
|
2017-11-27 14:08:18 +00:00
|
|
|
var config = require('../application/config.js');
|
2017-10-24 06:56:18 +00:00
|
|
|
var mail = require('../application/mail.js');
|
|
|
|
var database = require('../application/database.js');
|
|
|
|
var auth = require('../application/auth.js');
|
2017-10-19 10:47:05 +00:00
|
|
|
var path = require('path');
|
2017-05-30 06:06:14 +00:00
|
|
|
|
2017-09-27 15:44:51 +00:00
|
|
|
// Body parser middleware
|
2017-05-30 06:06:14 +00:00
|
|
|
app.use(bodyParser.json());
|
|
|
|
app.use(bodyParser.urlencoded({extended: true}));
|
|
|
|
|
2017-10-24 06:56:18 +00:00
|
|
|
app.use('/static', express.static(path.join(__dirname, '../static')));
|
2017-10-19 10:47:05 +00:00
|
|
|
|
2017-09-27 15:44:51 +00:00
|
|
|
// Load routes
|
2017-12-26 09:02:47 +00:00
|
|
|
app.use('/', require('../application/router.js'));
|
2017-06-07 13:28:42 +00:00
|
|
|
|
2017-05-31 12:55:41 +00:00
|
|
|
app.start = function() {
|
2017-11-27 14:08:18 +00:00
|
|
|
var listener = app.listen(config.app.port, function() {
|
2017-06-12 11:41:02 +00:00
|
|
|
var servicePath = 'http://' + listener.address().address + ':' + listener.address().port;
|
2017-05-31 12:55:41 +00:00
|
|
|
mail.init();
|
|
|
|
database.init();
|
2017-08-30 12:10:43 +00:00
|
|
|
database.testEmail();
|
2017-09-27 15:44:51 +00:00
|
|
|
|
2017-10-24 06:56:18 +00:00
|
|
|
let packageJson = require('../package.json');
|
2017-10-13 14:23:00 +00:00
|
|
|
console.log(`Web server ${packageJson.name} listening at: ${servicePath}`);
|
|
|
|
|
2017-11-27 14:08:18 +00:00
|
|
|
if (config.app.debug) {
|
2017-10-13 14:23:00 +00:00
|
|
|
console.log(`${packageJson.name} service debug mode enabled`);
|
2017-05-30 06:50:16 +00:00
|
|
|
}
|
|
|
|
});
|
2017-06-12 11:41:02 +00:00
|
|
|
return listener;
|
2017-05-30 06:50:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if (require.main === module) {
|
|
|
|
app.start();
|
|
|
|
}
|