salix/services/mailer/server.js

44 lines
1.3 KiB
JavaScript
Raw Normal View History

2017-05-30 06:06:14 +00:00
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');
var settings = require('./application/settings.js');
var mail = require('./application/mail.js');
var database = require('./application/database.js');
var auth = require('./application/auth.js');
var path = require('path');
2017-05-30 06:06:14 +00:00
// Body parser middleware
2017-05-30 06:06:14 +00:00
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
app.use('/static', express.static(path.join(__dirname, '/static')));
// Auth middleware
var requestToken = function(request, response, next) {
auth.init(request, response, next);
};
// Load routes
app.use('/', requestToken, require('./application/router.js'));
2017-06-07 13:28:42 +00:00
2017-05-31 12:55:41 +00:00
app.start = function() {
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();
database.testEmail();
2017-10-13 14:23:00 +00:00
let packageJson = require('./package.json');
console.log(`Web server ${packageJson.name} listening at: ${servicePath}`);
2017-05-31 12:55:41 +00:00
if (settings.app().debug) {
2017-10-13 14:23:00 +00:00
console.log(`${packageJson.name} service debug mode enabled`);
2017-05-30 06:50:16 +00:00
}
});
return listener;
2017-05-30 06:50:16 +00:00
};
if (require.main === module) {
app.start();
}