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

Commit

Permalink
add express-rate-limit (#291)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheJeterLP authored Mar 28, 2024
1 parent 695ea75 commit 6125085
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
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

0 comments on commit 6125085

Please sign in to comment.