38 lines
1.1 KiB
JavaScript
38 lines
1.1 KiB
JavaScript
var express = require('express');
|
|
var app = module.exports = express();
|
|
var bodyParser = require('body-parser');
|
|
var config = require('../application/config.js');
|
|
var mail = require('../application/mail.js');
|
|
var database = require('../application/database.js');
|
|
var path = require('path');
|
|
|
|
// Body parser middleware
|
|
app.use(bodyParser.json());
|
|
app.use(bodyParser.urlencoded({extended: true}));
|
|
|
|
app.use('/static', express.static(path.join(__dirname, '../static')));
|
|
|
|
// Load routes
|
|
app.use('/', require('../application/router.js'));
|
|
|
|
app.start = function(port) {
|
|
var listener = app.listen(port ? port : config.app.port, function() {
|
|
var servicePath = 'http://' + listener.address().address + ':' + listener.address().port;
|
|
mail.init();
|
|
database.init();
|
|
database.testEmail();
|
|
|
|
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();
|
|
}
|