2017-05-30 06:06:14 +00:00
|
|
|
/**
|
|
|
|
* Módulos necesarios
|
|
|
|
*/
|
|
|
|
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-06-01 07:58:24 +00:00
|
|
|
var settings = require('./application/settings.js');
|
|
|
|
var mail = require('./application/mail.js');
|
|
|
|
var database = require('./application/database.js');
|
2017-05-30 06:06:14 +00:00
|
|
|
|
|
|
|
// Middleware
|
|
|
|
app.use(bodyParser.json());
|
|
|
|
app.use(bodyParser.urlencoded({extended: true}));
|
|
|
|
|
|
|
|
// Cargar rutas
|
2017-06-01 07:58:24 +00:00
|
|
|
app.use('/', require('./application/router.js'));
|
2017-05-30 06:06:14 +00:00
|
|
|
|
2017-06-07 13:28:42 +00:00
|
|
|
app.use(function(err, req, res, next) {
|
|
|
|
console.error(err.message);
|
|
|
|
res.status(500).send('Something broke!');
|
|
|
|
});
|
|
|
|
|
2017-05-31 11:46:18 +00:00
|
|
|
// Iniciar escucha del servidor
|
2017-05-31 12:55:41 +00:00
|
|
|
app.start = function() {
|
2017-06-12 11:41:02 +00:00
|
|
|
var listener = app.listen(settings.app().port, function() {
|
|
|
|
var servicePath = 'http://' + listener.address().address + ':' + listener.address().port;
|
2017-05-31 12:55:41 +00:00
|
|
|
mail.init();
|
|
|
|
database.init();
|
2017-06-12 11:41:02 +00:00
|
|
|
console.log('Web service ' + settings.app().name.toUpperCase() + ' listening at: ' + servicePath);
|
|
|
|
console.log('Browse your REST API at: ' + servicePath + '/mailer');
|
2017-05-31 12:55:41 +00:00
|
|
|
if (settings.app().debug) {
|
2017-06-12 11:41:02 +00:00
|
|
|
console.log(settings.app().name.toUpperCase() + ' 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();
|
|
|
|
}
|
2017-05-30 06:06:14 +00:00
|
|
|
|
2017-05-30 06:06:14 +00:00
|
|
|
|