-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
45 lines (35 loc) · 1.2 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
43
44
45
const express = require("express");
const bodyParser = require("body-parser");
const morgan = require("morgan");
const { rateLimit } = require("express-rate-limit");
const cors = require("cors");
const { PORT } = require("./config/serverConfig");
const router = require("./routes");
// const client = require("./redis/client");
const startServer = () => {
const app = express();
const limiter = rateLimit({
windowMs: 2 * 60 * 1000, // 15 minutes
limit: 100, // Limit each IP to 100 requests per `window` (here, per 15 minutes).
message: { message: "To many request you block by rate limiter"}
});
// to see every log
app.use(morgan("combined"));
// cors
app.use(cors());
// Apply the rate limiting middleware to allow number of requests.
app.use(limiter);
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
//All the routes handled by here
app.use("/", router);
app.listen(PORT, async () => {
console.log("start server on :", PORT);
// redis
// const result = await client.get("user:1");
// const result = await client.set("msg:1", "hii from api gateway");
// const result = await client.expire("msg:1", 10);
// console.log(result);
});
};
startServer();