Skip to content

[question] How does hono-rate-limiter work with many different configs? #6

Answered by MathurAditya724
flipvh asked this question in Q&A
Discussion options

You must be logged in to vote

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.

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"),
);

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by MathurAditya724
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #5 on April 04, 2024 10:47.