46 lines
1.2 KiB
JavaScript
46 lines
1.2 KiB
JavaScript
/**
|
|
* Módulos necesarios
|
|
*/
|
|
var express = require('express');
|
|
var app = module.exports = express();
|
|
var bodyParser = require('body-parser');
|
|
var settings = require('./application/settings.js');
|
|
var mail = require('./application/mail.js');
|
|
var database = require('./application/database.js');
|
|
var auth = require('./application/auth.js');
|
|
|
|
// Body parser middleware
|
|
app.use(bodyParser.json());
|
|
app.use(bodyParser.urlencoded({extended: true}));
|
|
|
|
// Auth middleware
|
|
var requestToken = function(request, response, next) {
|
|
auth.init(request, response, next);
|
|
};
|
|
|
|
app.use(requestToken);
|
|
|
|
// Load routes
|
|
app.use('/', require('./application/router.js'));
|
|
|
|
app.start = function() {
|
|
var listener = app.listen(settings.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 (settings.app().debug) {
|
|
console.log(`${packageJson.name} service debug mode enabled`);
|
|
}
|
|
});
|
|
return listener;
|
|
};
|
|
|
|
if (require.main === module) {
|
|
app.start();
|
|
}
|