42 lines
1.2 KiB
JavaScript
42 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');
|
|
|
|
// Middleware
|
|
app.use(bodyParser.json());
|
|
app.use(bodyParser.urlencoded({extended: true}));
|
|
|
|
// Cargar rutas
|
|
app.use('/', require('./application/router.js'));
|
|
|
|
app.use(function(err, req, res, next) {
|
|
console.error(err.message);
|
|
res.status(500).send('Something broke!');
|
|
});
|
|
|
|
// Iniciar escucha del servidor
|
|
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();
|
|
console.log('Web server ' + settings.app().name.toUpperCase() + ' listening at: ' + servicePath);
|
|
console.log('Browse your REST API at: ' + servicePath + '/mailer');
|
|
if (settings.app().debug) {
|
|
console.log(settings.app().name.toUpperCase() + ' service debug mode enabled');
|
|
}
|
|
});
|
|
return listener;
|
|
};
|
|
|
|
if (require.main === module) {
|
|
app.start();
|
|
}
|