标签: express-rate-limit

具有静态的快速速率限制

我有带有 Express 和 React 捆绑包的 VPS。问题是,当我从前端访问 API 时,我得到相同的 IP 地址(localhost),因此我无法正确使用express-rate-limit。

我有一个快递服务器:

const apiLimiter = rateLimit({
  windowMs: 1 * 60 * 1000,
  max: 30
});

app.use("/api/", apiLimiter);

app.use(express.static('client/build'));
app.get('*', (req, res) => {
  res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'));
});
Run Code Online (Sandbox Code Playgroud)

和前端的 package.json 中的代理配置:

"proxy": "http://localhost:3000/"
Run Code Online (Sandbox Code Playgroud)

如何修复它并正确使用express-rate-limit?

node.js express reactjs express-rate-limit

5
推荐指数
1
解决办法
565
查看次数

Deno 部署 - 请求时未定义 IP 地址

我在 Deno 上使用expressmongo,并且我也尝试使用express-rate-limit,但是,我在速率限制上收到以下错误,因为request.ip未定义:

ValidationError: An undefined 'request.ip' was detected. This might indicate a misconfiguration or the connection being destroyed prematurely. See https://express-rate-limit.github.io/ERR_ERL_UNDEFINED_IP_ADDRESS/ for more information.
    at Object.ip (file:///node_modules/.deno/express-rate-limit@7.1.5/node_modules/express-rate-limit/dist/index.mjs:97:13)
    at Object.wrappedValidations.<computed> [as ip] (file:///node_modules/.deno/express-rate-limit@7.1.5/node_modules/express-rate-limit/dist/index.mjs:296:22)
    at Object.keyGenerator (file:///node_modules/.deno/express-rate-limit@7.1.5/node_modules/express-rate-limit/dist/index.mjs:549:20)
    at file:///node_modules/.deno/express-rate-limit@7.1.5/node_modules/express-rate-limit/dist/index.mjs:601:32
    at Object.runMicrotasks (ext:core/01_core.js:934:26)
    at processTicksAndRejections (ext:deno_node/_next_tick.ts:53:10)
    at runNextTicks (ext:deno_node/_next_tick.ts:71:3)
    at eventLoopTick (ext:core/01_core.js:189:21)
    at async file:///node_modules/.deno/express-rate-limit@7.1.5/node_modules/express-rate-limit/dist/index.mjs:583:5 {
  name: "ValidationError",
  code: "ERR_ERL_UNDEFINED_IP_ADDRESS",
  help: "https://express-rate-limit.github.io/ERR_ERL_UNDEFINED_IP_ADDRESS/"
}
Run Code Online (Sandbox Code Playgroud)

我在一个类似的问题上找到了这个答案,建议添加app.set('trust proxy', 1);我尝试过,但 ip 仍然未定义。

如何重现:

"use …
Run Code Online (Sandbox Code Playgroud)

mongodb node.js express deno express-rate-limit

5
推荐指数
0
解决办法
82
查看次数

我可以使用express-rate-limit为同一条路线设置多个速率限制吗?

我可以为我的 Express 服务器设置全局rateLimit,并rateLimit为某些路由设置更严格的限制吗?

例如:

const globalLimit = rateLimit({
  windowMs: 60 * 60 * 1000,        // 1 HOUR
  max: 500                         // MAX 500 REQUESTS
});

const apiLimit = rateLimit({
  windowMs: 60 * 60 * 1000,        // 1 HOUR
  max: 100                         // MAX 100 REQUESTS
});

const someRouteLimit = rateLimit({
  windowMs: 60 * 60 * 1000,        // 1 HOUR
  max: 10                          // MAX 10 REQUESTS
});


app.use("/", globalLimit);         // ALL ROUTES WILL BE LIMITED BY THE globalLimit
app.use("/api", …
Run Code Online (Sandbox Code Playgroud)

node.js express express-rate-limit

4
推荐指数
1
解决办法
1625
查看次数

标签 统计

express ×3

express-rate-limit ×3

node.js ×3

deno ×1

mongodb ×1

reactjs ×1