-
Notifications
You must be signed in to change notification settings - Fork 4
/
server.web.js
42 lines (32 loc) · 997 Bytes
/
server.web.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
34
35
36
37
38
39
40
41
42
'use strict';
var http = require('http'); // TODO: https?
var express = require('express');
var compression = require('compression');
var util = require('./util');
module.exports = function (port, index, plugin, callback) {
var app = express();
var server = http.createServer(app);
app.use(function (req, res, next) {
util.log('web ' + req.ip + ' ' + req.url);
next();
});
app.use(compression());
app.use('/lib', express.static('./lib', {}));
app.use('/', express.static('./web', {
extensions: 'html',
fallthrough: false,
index: index,
}));
app.use(function (err, req, res, next) {
if (err.status === 404) {
util.log('web not found ' + req.path);
} else {
util.log('web error ' + err.status + ' ' + req.path);
util.err(err);
}
res.status(err.status || 500);
res.end();
});
plugin(server);
server.listen(port, callback);
};