Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| caa720352f |
@@ -4,28 +4,12 @@ import env from "dotenv";
|
|||||||
env.config();
|
env.config();
|
||||||
const app = express();
|
const app = express();
|
||||||
const port = 7001;
|
const port = 7001;
|
||||||
import { rateLimit } from "express-rate-limit";
|
|
||||||
|
|
||||||
app.use(cors());
|
app.use(cors());
|
||||||
app.use(express.urlencoded({ extended: true }));
|
app.use(express.urlencoded({ extended: true }));
|
||||||
app.set("view engine", "ejs");
|
app.set("view engine", "ejs");
|
||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
|
|
||||||
const limits = {
|
|
||||||
time: 1, // = 1 minute
|
|
||||||
requests: 10, // = maximum 10 requests
|
|
||||||
};
|
|
||||||
|
|
||||||
const limiter = rateLimit({
|
|
||||||
windowMs: limits.time * 60 * 1000,
|
|
||||||
limit: limits.requests,
|
|
||||||
standardHeaders: "draft-8", // draft-6: `RateLimit-*` headers; draft-7 & draft-8: combined `RateLimit` header
|
|
||||||
legacyHeaders: false, // Disable the `X-RateLimit-*` headers.
|
|
||||||
ipv6Subnet: 56, // Set to 60 or 64 to be less aggressive, or 52 or 48 to be more aggressive
|
|
||||||
});
|
|
||||||
|
|
||||||
app.use(limiter);
|
|
||||||
|
|
||||||
app.get("/", (req, res) => {
|
app.get("/", (req, res) => {
|
||||||
res.render("index.ejs", { title: port });
|
res.render("index.ejs", { title: port });
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user