Skip to content

Commit 2ab0d49

Browse files
Copilothuangyiirene
andcommitted
Changes before error encountered
Co-authored-by: huangyiirene <7665279+huangyiirene@users.noreply.github.com>
1 parent 5f82b1c commit 2ab0d49

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

packages/cli/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"vite": "^5.0.0",
3737
"@vitejs/plugin-react": "^4.2.1",
3838
"express": "^4.21.2",
39+
"express-rate-limit": "^7.4.1",
3940
"js-yaml": "^4.1.0",
4041
"@object-ui/react": "workspace:*",
4142
"@object-ui/components": "workspace:*"

packages/cli/src/commands/start.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import express from 'express';
2+
import rateLimit from 'express-rate-limit';
23
import { existsSync } from 'fs';
34
import { join, resolve } from 'path';
45
import chalk from 'chalk';
@@ -37,6 +38,18 @@ export async function start(options: StartOptions) {
3738
const port = parseInt(options.port);
3839
const host = options.host;
3940

41+
// Configure rate limiting to prevent abuse
42+
const limiter = rateLimit({
43+
windowMs: 15 * 60 * 1000, // 15 minutes
44+
max: 1000, // Limit each IP to 1000 requests per windowMs
45+
message: 'Too many requests from this IP, please try again later.',
46+
standardHeaders: true, // Return rate limit info in the `RateLimit-*` headers
47+
legacyHeaders: false, // Disable the `X-RateLimit-*` headers
48+
});
49+
50+
// Apply rate limiting to all routes
51+
app.use(limiter);
52+
4053
// Serve static files from dist directory
4154
app.use(express.static(distPath));
4255

0 commit comments

Comments
 (0)