[question] How does hono-rate-limiter work with many different configs? #6
-
Hope its ok to ask a question. I am considering replacing our rate-limiter in our hono project with this one! I am hoping to get a solution that is less verbose as our current code: https://github.com/cellajs/cella/blob/1b4aaf59dc8d888f35e8d8aefc25df4dbae0e6e7/backend/src/middlewares/rate-limiter/index.ts Suppose i ultimately want about 5 to 10 different rate-limiter configs, to handle specific scenarios in specific routes, what would that look like with hono-rate-limiter? Can I just pass different options to the same instance? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
The best way could be to define the common props like the app.get(
"/",
rateLimiter({
...defaults,
windowMs: 10_000, // 10 seconds
limit: 10
}),
(c) => c.text("Base"),
);
app.get(
"/another",
rateLimiter({
...defaults,
windowMs: 60_000, // 1 min
limit: 30
}),
(c) => c.text("Another"),
); |
Beta Was this translation helpful? Give feedback.
-
I like that! Thanks! |
Beta Was this translation helpful? Give feedback.
The best way could be to define the common props like the
store
,keyGenerator
, etc. Then you could just define the custom config for all the routes that you want to rate limit. You can also provide prefixes to chain multiple limiters together.