koajs / ratelimit

Rate limiter middleware
MIT License
485 stars 57 forks source link

Error in koa-ratelimit/limiter/memory.js:34:3: ".id required" #61

Closed fermmm closed 11 months ago

fermmm commented 3 years ago

I see this error multiple times in the logs of my server. Can you tell me what could be the problem? I'm not calling the Limiter class or constructor in my code (at least not directly). I'm using 4.2.0 version. The rate limiter is working but sometimes I get this error on the logs.

AssertionError [ERR_ASSERTION]: .id required
      at new Limiter (/home/fer/polyamory-dates-server/node_modules/koa-ratelimit/limiter/memory.js:34:3)
      at ratelimit (/home/fer/polyamory-dates-server/node_modules/koa-ratelimit/index.js:74:17)
      at dispatch (/home/fer/polyamory-dates-server/node_modules/koa-compose/index.js:42:32)
      at cors (/home/fer/polyamory-dates-server/node_modules/@koa/cors/index.js:56:38)
      at dispatch (/home/fer/polyamory-dates-server/node_modules/koa-compose/index.js:42:32)
      at /home/fer/polyamory-dates-server/node_modules/koa-compose/index.js:34:12
      at Application.handleRequest (/home/fer/polyamory-dates-server/node_modules/koa/lib/application.js:168:12)
      at Server.handleRequest (/home/fer/polyamory-dates-server/node_modules/koa/lib/application.js:150:19)
      at Server.emit (events.js:315:20)
      at Server.<anonymous> (/home/fer/.nvm/versions/node/v14.16.1/lib/node_modules/pm2/node_modules/@pm2/io/src/metrics/httpMetrics.ts:181:25)

I suspect the problem is in the index.js line 40. Maybe you should replace the line with this one: id: ctx => ctx.request.ip

3imed-jaberi commented 3 years ago

is it work with id: ctx => ctx.request.ip ?!