-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
44 lines (32 loc) · 930 Bytes
/
app.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
const express = require("express");
const cors = require("cors");
const morgan = require("morgan");
const rateLimit = require("express-rate-limit");
const app = express();
// API requests
// JSON middleware for incoming requests
app.use("/api", express.json());
// Enable cors
app.use("/api", cors());
// enable logging
app.use(morgan('combined'))
// Rate limiting
// returns 429 'Too many requests' error if limit is hit
const limiter = rateLimit({
windowMs: 10 * 60 * 1000, //10 minutes
max: 5, //max number of requests during timeframe
message: `{"limit error": "Too many requests"}`,
});
app.use("/api", limiter);
app.set("trust proxy", 1);
app.use("/api", require("./routes"));
// Health check
const healthcheck_routes = express.Router();
healthcheck_routes.get(
"/",
async (req, res) => {
res.status(200).send("ok")
}
)
app.use("/health", healthcheck_routes);
module.exports = app // for testing