Giter Site home page Giter Site logo

tunnckocore / koa-better-ratelimit Goto Github PK

View Code? Open in Web Editor NEW
38.0 4.0 6.0 4.33 MB

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

Home Page: http://j.mp/1stW47C

License: MIT License

JavaScript 100.00%
koajs koa filter ip id

koa-better-ratelimit's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

koa-better-ratelimit's Issues

support id option

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; }

Options is not defined

  1. Hi. Trying to test:

const Koa=require('koa2');
const limiter=require('./index.js');
const app=new Koa();
app.use(limiter({
id:function(){return '0.0.0.0'},
duration:1000*20,
max:2,
throw:true
}))
app.use(ctx=>{
ctx.body="hello world";
});
app.listen(5000);
console.log('Server started at port 5000');

But
ReferenceError: options is not defined
at betterRatelimit (/home/globik/koa-better-ratelimit/index.js:33:8)
at dispatch (/home/globik/koa-better-ratelimit/node_modules/koa-compose/index.js:44:32)
at next (/home/globik/koa-better-ratelimit/node_modules/koa-compose/index.js:45:18)
at createGenerator (/home/globik/koa-better-ratelimit/node_modules/koa-convert/index.js:24:16)
at createGenerator.next ()
at Object. (/home/globik/koa-better-ratelimit/node_modules/koa-ip-filter/index.js:77:20)
at Generator.next ()
at onFulfilled (/home/globik/koa-better-ratelimit/node_modules/co/index.js:65:19)
at /home/globik/koa-better-ratelimit/node_modules/co/index.js:54:5
at Object.co (/home/globik/koa-better-ratelimit/node_modules/co/index.js:50:10)
What for the "options"?
2. Where can I find koa-better-ratelimit version 3.0?

Multiple clients

Perhaps I'm being really stupid, but this line index.js#L95 seems to suggest only adjacent requests from the same IP will be rate limited. If another request comes in from another IP address, previous rate limit records will be ignored and a new one created.

I couldn't figure out an easy way to write a test for this.

Koa 2 full support for async/await [feature request]

Currently throwing this alert because of old generator signature.

0|react-ap | Mon, 09 Oct 2017 08:47:12 GMT koa deprecated Support for generators will be removed in v3. See the documentation for examples of how to convert old middleware https://github.com/koajs/koa/blob/master/docs/migration.md
0|react-ap |     at Object.<anonymous> (/Users/damz/Desktop/react-app/index.js:23:5)
0|react-ap |     at Module._compile (module.js:624:30)
0|react-ap |     at Object.Module._extensions..js (module.js:635:10)
0|react-ap |     at Module.load (module.js:545:32)
0|react-ap |     at tryModuleLoad (module.js:508:12)
0|react-ap |     at Function.Module._load (module.js:500:3)

Caveats of in-memory storage

I understand that this was built using in-memory stores by design but it might be helpful to others to add a caveats section to the README.

This is so that people understand that this type of store will only work effectively if you're running on a single machine or you want to enforce limits on a per-machine basis.

If I understood correctly...

This middleware helps to mitigate DoS attacks, so if I want to limit any user to 5 requests per minute, I'd write it like this:

app.use(limit({
  duration: 1000 * 60 * 1,
  max: 5
}));

Right?

apply feross/standard and stuff

  • and cleanup root
  • keep a changelog (adheres semver/ferver)
  • rename readme, license, etc stuff
  • update/fix readme/badges/links style

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.