forked from sqwid-app/sqwid-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
41 lines (33 loc) · 1.1 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
require ('dotenv').config ();
const express = require ('express');
const morgan = require ('morgan');
const helmet = require ('helmet');
const rateLimit = require ('express-rate-limit')
const app = express ();
const port = process.env.PORT || 8080;
const firebase = require ('./lib/firebase');
const redisClient = require ('./lib/redis');
const limiter = rateLimit ({
windowMs: 1 * 60 * 1000, // 1 minute
max: 60, // Limit each IP to 60 requests per `window`
standardHeaders: true,
legacyHeaders: false,
})
const cors = require ('cors');
app.set ('trust proxy', 2);
app.use (morgan ('dev'));
app.use (helmet ());
app.use (cors ({origin: '*'}));
app.use (express.json ({ limit: "50mb" }));
app.use (express.urlencoded ({extended: true, limit: "50mb"}));
app.use (limiter);
const getRoutes = require ('./routes/index');
app.use ('/', getRoutes ());
// app.get ('/ip', (request, response) => response.send(request.ip))
app.use(function (err, req, res, next) {
console.error (err.stack)
res.status (500).send ('Something broke!')
})
app.listen (port, () => {
console.log (`Listening on port ${port}`);
});