-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
39 lines (32 loc) · 1.07 KB
/
app.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
var express = require('express');
var conf = require('./server/conf');
var methodOverride = require('method-override');
var app = module.exports = express();
app.use(express.compress());
// app.use(express.bodyParser({ strict: false }));
app.use(methodOverride('X-HTTP-Method-Override'));
app.use(function() {
var staticServer = express.static(conf.static.path, {
maxAge: conf.static.ttl,
setHeaders: function(res, path) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET');
}
});
return function(req, res, next) {
console.log(req.header('host'), conf.static.host);
if (req.header('host') !== conf.static.host) {
return next();
}
console.log(req.url);
staticServer(req, res, function() {
res.contentType('text/plain');
res.send(404, 'Not Found')
});
};
}());
app.use(app.router);
require('./server/endpoints');
var server = app.listen(conf.http.port, conf.http.hostname, function() {
console.log('Express server listening on %s:%s', conf.http.hostname, conf.http.port + '...');
});