forked from ionic-team/ionic-site
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
62 lines (50 loc) · 1.6 KB
/
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
require('dotenv').config({silent: true});
const express = require('express');
const app = express();
const compress = require('compression');
const config = require('./server/config');
const cookieParser = require('cookie-parser');
const expressNunjucks = require('express-nunjucks');
const helmet = require('helmet');
const pageNotFound = require('./server/pageNotFound');
const processRequest = require('./server/processRequest');
const router = require('./server/router');
const tools = require('./server/tools');
// rate limit POST requests
if (config.REDIS_URL) {
var redis = require('redis').createClient(config.REDIS_URL);
var limiter = require('express-limiter')(app, redis);
// rate limit POST requests
limiter({
path: '*',
method: 'post',
lookup: ['headers.CF-Connecting-IP'],
// 10 requests per hour
total: 10,
expire: 1000 * 60 * 60
})
}
process.env.PWD = process.cwd();
console.log('PWD', process.env.PWD);
app.set('trust proxy', true);
app.use(compress());
app.use(cookieParser());
app.use(helmet());
app.use(processRequest);
app.set('views', __dirname + '/server/pages');
expressNunjucks(app, {
noCache: !config.PROD,
autoescape: false
});
app.enable('etag');
app.use(router(app));
app.use(express.static(process.env.PWD + '/_site/', {
etag: true
}));
app.use(pageNotFound);
// bind the app to listen for connections on a specified port
app.listen(config.PORT, function() {
// Render some console log output
console.log('Listening on port ' + config.PORT);
tools.bustCloudflareCache();
});