Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

add express-rate-limit #291

Merged
merged 1 commit into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"cookie-parser": "^1.4.6",
"cors": "^2.8.5",
"express": "^4.19.2",
"express-rate-limit": "^7.2.0",
"express-session": "^1.18.0",
"jsonwebtoken": "^9.0.2",
"jwt-decode": "^4.0.0",
Expand Down
7 changes: 7 additions & 0 deletions src/main/typescript/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Required external modules
*/
import express, { Application } from 'express';
import RateLimit from 'express-rate-limit';
import cors from 'cors';
import mongoose from 'mongoose';
import session from 'express-session';
Expand Down Expand Up @@ -38,6 +39,11 @@ import path from 'node:path';
* App Variables
*/
const app: Application = express();
const limiter = RateLimit({
// 15 minutes
windowMs: 15 * 60 * 1000,
limit: 100,
});

/**
* Database connection
Expand All @@ -53,6 +59,7 @@ app.use(cors({
origin: server_settings.frontend_url,
credentials: true,
}));
app.use(limiter);
app.use(cookies());
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
Expand Down
Loading