-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🤗 [Question]: Rate limit per path #2924
Comments
Thanks for opening your first issue here! 🎉 Be sure to follow the issue template! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord |
Is anyone know decision? |
Yes. You can use a new rate limiter middleware handler for each route. Either set a route on |
Here is an example with app.Use package main
import (
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/limiter"
)
func main() {
app := fiber.New()
// …
// Custom rate limits for specific paths
app.Use("/auth", limiter.New(limiter.Config{
Max: 10, // Requests per minute for /auth
Expiration: 1 * time.Minute,
}))
app.Use("/auth/", limiter.New(limiter.Config{
Max: 5, // Requests per minute for /auth/
Expiration: 1 * time.Minute,
}))
app.Use("/auth/realms", limiter.New(limiter.Config{
Max: 25, // Requests per minute for /auth/realms
Expiration: 1 * time.Minute,
}))
// Add your routes here
app.Get("/auth", handler.RedirectHandler)
app.Get("/auth/", handler.RedirectHandler)
app.Get("/auth/realms", handler.RedirectHandler)
// …
// Start the server
app.Listen(":3000")
} |
@sixcolors thanks I did the same way and it works |
Question Description
is it possible to add rate limiting functionality per path e.g. have different rate limiting logic for each path below?
app.Get("/auth", handler.RedirectHandler) - rate limit by 10 for 1 min
app.Get("/auth/", handler.RedirectHandler) - rate limit by 5 for 1 min
app.Get("/auth/realms", handler.RedirectHandler) - rate limit by 25 for 1 min
Code Snippet (optional)
No response
Checklist:
The text was updated successfully, but these errors were encountered: