-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
44 lines (32 loc) · 1.03 KB
/
index.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
43
44
var express= require('express');
var compression = require('compression');
var path = require('path');
var cors = require('cors');
var app = express();
var static_path = path.join(__dirname, './');
app.enable('trust proxy');
app.use(compression());
app.options('/api/currentTime', cors());
app.get('/api/currentTime', cors(), function(req, res) {
res.send({ time: new Date() });
});
app.route('/').get(function(req, res) {
res.header('Cache-Control', "max-age=60, must-revalidate, private");
res.sendFile('index.html', {
root: static_path
});
});
function nocache(req, res, next) {
res.header('Cache-Control', 'private, no-cache, no-store, must-revalidate');
res.header('Expires', '-1');
res.header('Pragma', 'no-cache');
next();
}
app.use('/', express.static(static_path, {
maxage: 31557600
}));
var server = app.listen(process.env.PORT || 5000, function () {
var host = server.address().address;
var port = server.address().port;
console.log('Example app listening at http://%s:%s', host, port);
});