-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathserver.js
33 lines (27 loc) · 893 Bytes
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
var fs = require('fs');
var http = require('http');
var express = require('express');
var mlf = require('./lib/app.js');
var logger = require('./lib/logger.js');
var settings = require('./lib/settings.js');
try {
mlf.createApp().then(function(mlfApp) {
var app = express();
// Log all requests to the server
app.use(function logRequests(req, res, next) {
logger.logRequest(req);
next();
});
app.get('/', function(req, res) {
res.redirect(settings.base_path);
});
app.use(settings.base_path, mlfApp);
var httpServer = http.createServer(app).listen(settings.server_port, function() {
var host = httpServer.address().address;
var port = httpServer.address().port;
logger.log('Server listening at http://' + host + ':' + port);
});
}).fail(logger.logException).done();
} catch (err) {
logger.logException(err);
}