-
Notifications
You must be signed in to change notification settings - Fork 17
/
index.js
35 lines (27 loc) · 1014 Bytes
/
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
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.use(bodyParser.json());
app.use(bodyParser.urlencoded({ 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}!`));