tunnckoCore / koa-better-ratelimit

:rocket: Smart and easy request rate limiter for your APIs built on `koa`, using `koa-ip-filter`. Support custom stores, custom ID, custom error messages and custom headers.
http://j.mp/1stW47C
MIT License
38 stars 6 forks source link

support id option #6

Open jedahan opened 9 years ago

jedahan commented 9 years ago

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; }
tunnckoCore commented 9 years ago

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

tunnckoCore commented 9 years ago

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

tunnckoCore commented 9 years ago

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 commented 9 years ago

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

jedahan commented 9 years ago

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 :)

tunnckoCore commented 9 years ago

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 commented 9 years ago

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.

jedahan commented 9 years ago

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.

tunnckoCore commented 9 years ago

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

tunnckoCore commented 9 years ago

@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!

bishtawi commented 9 years ago

@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.

tunnckoCore commented 9 years ago

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

apisurfer commented 9 years ago

+1. Would love to see this feature.

tunnckoCore commented 9 years ago

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

tunnckoCore commented 8 years ago

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