salix/services/mailer/server.js

40 lines
965 B
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() {
return app.listen(settings.app().port, function() {
mail.init();
database.init();
console.log('Mailer started at port:' + settings.app().port);
if (settings.app().debug) {
console.log('Debug mode enabled');
}
});
};
if (require.main === module) {
app.start();
}