salix/services/mailer/server.js

37 lines
1.1 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');
// Body parser middleware
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
// 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();
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();
}