Skip to content

Commit 196a0c3

Browse files
committed
fix: allow rate limit trust proxy
1 parent 30aba9d commit 196a0c3

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

server.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ const remixHandler = createRequestHandler({
2323

2424
const app = express();
2525

26+
app.set('trust proxy', true);
27+
2628
app.use(
2729
cors({
2830
// 允许所有来源访问,生产环境中应该设置为特定的域名
@@ -41,6 +43,7 @@ const globalLimiter = rateLimit({
4143
standardHeaders: 'draft-7', // 返回标准的 RateLimit 头信息
4244
legacyHeaders: false, // 禁用旧的 X-RateLimit 头信息
4345
message: '请求过于频繁,请稍后再试',
46+
proxy: true,
4447
});
4548

4649
// 针对聊天 API 的特殊限流中间件
@@ -52,6 +55,7 @@ const chatApiLimiter = rateLimit({
5255
message: '聊天请求过于频繁,请稍后再试',
5356
// 仅对聊天 API 路由应用此限制
5457
skip: (req) => !req.url.includes('/api/chat'),
58+
proxy: true,
5559
});
5660

5761
app.use((req, res, next) => {

0 commit comments

Comments
 (0)