-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
39 lines (30 loc) · 964 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
const express = require("express");
const rateLimit = require("express-rate-limit");
const app = express();
const port = 5000;
const limiter = rateLimit({
windowMs: 15 * 60 * 1000, // 15 Minites Interval
max: 6, // limit each IP to 5 request.
message: "Too many API requests from this IP ,please try again after 15 min",
});
const loginAccountlimiter = rateLimit({
windowMs: 15 * 60 * 1000, // 15 Minites Interval
max: 6, // limit each IP to 5 request.
message: "Too many login requests. ",
});
// app.use(limiter); -> will work for all routes
app.use("/api", limiter);
app.get("/api/v1", function (req, res) {
res.json([
{
id: 1,
title: "NodeJS",
description:
"Javascript runtime built on Chrome's VS Javascript engine .",
},
]);
});
app.get("/login", loginAccountlimiter, function (req, res) {
res.send("Imaginary Login form.");
});
app.listen(port, () => console.info(`App listen on port ${port}`));