-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.js
42 lines (33 loc) · 1.28 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
const express = require('express')
const config = require('./config.js');
const bodyParser = require('body-parser');
const multer = require('multer');
const slowDown = require("express-slow-down");
const upload = multer();
let app = express()
const port = config('PORT');
// boot up browser
require('./puppeteer');
require('./purge_expired');
if (config('TRUST_PROXY')) { // only if you're behind a reverse proxy (Heroku, Bluemix, AWS if you use an ELB, custom Nginx setup, etc)
app.enable("trust proxy");
}
const speedLimiter = slowDown({
windowMs: config('RATE_LIMIT_WINDOW') * 60 * 1000,
delayAfter: config('RATE_LIMIT_DELAY_AFTER'),
delayMs: config('RATE_LIMIT_DELAY_MS')
});
app.all('*', function(req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'PUT, GET, POST, DELETE, OPTIONS');
res.header('Access-Control-Allow-Headers', 'Content-Type');
next();
});
app.use(bodyParser.json({ limit: '50mb', extended: true }));
app.use(bodyParser.urlencoded({ limit: '50mb', extended: true }));
app.use(upload.array());
app.use(express.static('static'))
app.use(speedLimiter);
app = require('./routes').register(app);
app.use(express.static('static'));
app.listen(port, () => console.log(`Example app listening on port ${port}!`));