koa-better-ratelimit icon indicating copy to clipboard operation
koa-better-ratelimit copied to clipboard

support id option

Open jedahan opened this issue 10 years ago • 15 comments

I want to be able to set up my own custom id functions, like in koa-ratelimit:

id: function (context) {
    return context.ip;
  }

In particular, I am trying to limit the rate of my entire application, not just per-user, so my custom id function might look like:

id: function () { return -1; }

jedahan avatar Dec 15 '14 19:12 jedahan

Yea, i see that when PR appears in koa-ratelimit and i'm thinking of it.

tunnckoCore avatar Dec 15 '14 19:12 tunnckoCore

It would be great if you can PR also with tests.

tunnckoCore avatar Dec 15 '14 19:12 tunnckoCore

Its not so easy because of using ipchecker's checks here

Hm.. okey, I'll look what can I create, as soon as possible. PRs welcome.

tunnckoCore avatar Dec 15 '14 20:12 tunnckoCore

@jedahan why you want to use koa-better-body?

tunnckoCore avatar Dec 15 '14 23:12 tunnckoCore

I'm confused what does koa-better-body has to do with my request. Unfortunately I don't have the time to submit a pull request, though I would like to. This is a request from a friend of mine, just trying to help him out :)

jedahan avatar Dec 17 '14 19:12 jedahan

Right.

I'm confused what does koa-better-body has to do with my request

It's simple, just limiting the requests per ip. And if he dont need to define custom error msgs, blacklisting ips, dont need db saving and etc, he should use some other simpler middleware

tunnckoCore avatar Dec 17 '14 22:12 tunnckoCore

Im thinking of to decouple it to separate modules at some point or concept for adding middleware to this middleware - i think it would be good. At this point we have tj's node-ratelimiter, but i believe it can be simpler.

tunnckoCore avatar Dec 17 '14 22:12 tunnckoCore

Ahh yes. That makes sense. Any middleware that can take a function, and yield a 429 ratelimit would do. Much simpler. Thanks for being patient explaining this to me.

jedahan avatar Dec 18 '14 17:12 jedahan

No worries. Try middlewares such as koa-ratelimit and koa-limit

tunnckoCore avatar Dec 18 '14 20:12 tunnckoCore

@jedahan I'll do this tonight and will release v3.0.0, because significant refactoring of the codebase and following ferver version scheme.

I'll start in clear v3 branch, stay tuned. Thank you guys!

tunnckoCore avatar Mar 24 '15 21:03 tunnckoCore

@tunnckoCore Do you have an ETA on when you plan on making v3 live? I need this feature as my server is sitting behind a load balancer and the IP address I need to rate limit is stored in X-Forwarded-For header.

bishtawi avatar Jun 03 '15 03:06 bishtawi

Do you have an ETA on when you plan on making v3 live

maximum the end of the week.

you may want to review https://github.com/tunnckoCore/koa-ip-filter

tunnckoCore avatar Jun 03 '15 08:06 tunnckoCore

+1. Would love to see this feature.

apisurfer avatar Jun 14 '15 14:06 apisurfer

@bishtawi @popc0rn sorry guys but I have a bad cold. Try koa-ip-filter. :)

tunnckoCore avatar Jun 14 '15 18:06 tunnckoCore

Finally, v3 will come maximum at the end of the week. After I finish https://github.com/tunnckoCore/koa-better-body/pull/34.

tunnckoCore avatar Apr 07 '16 04:04 tunnckoCore