Skip to content

Commit 9004ecb

Browse files
committed
add rate limiter for endpoints
1 parent 4035c32 commit 9004ecb

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

samples/agentic-langgraph/app/package-lock.json

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/agentic-langgraph/app/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"@langchain/openai": "^0.6.3",
1616
"@langchain/tavily": "^0.1.4",
1717
"express": "^4.21.2",
18+
"express-rate-limit": "^8.0.1",
1819
"ts-node": "^10.9.2"
1920
},
2021
"devDependencies": {

samples/agentic-langgraph/app/server.mts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
import express from "express";
22
import { getAgentOutputAsString } from "./agent.mts";
33
import path from "path";
4+
import rateLimit from "express-rate-limit";
45

56
const app = express();
7+
8+
const limiter = rateLimit({
9+
windowMs: 60 * 1000, // 1 minute
10+
max: 30, // limit each IP to 30 requests per windowMs
11+
standardHeaders: true,
12+
legacyHeaders: false,
13+
});
14+
615
app.use(express.json());
716
app.use(express.static(path.join(process.cwd(), "public")));
17+
app.use(limiter);
818

919
app.post("/agent", async (req, res) => {
1020
const input = req.body.input;

0 commit comments

Comments
 (0)