Coder Social home page Coder Social logo

Comments (5)

sixcolors avatar sixcolors commented on June 13, 2024 3

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")
}

from fiber.

welcome avatar welcome commented on June 13, 2024

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

from fiber.

bigboiii300 avatar bigboiii300 commented on June 13, 2024

Is anyone know decision?

from fiber.

sixcolors avatar sixcolors commented on June 13, 2024

Yes. You can use a new rate limiter middleware handler for each route.

Either set a route on app.Use with the middleware handler (works with groups too), or apply the handler in the app.Get

https://docs.gofiber.io/guide/routing#middleware

from fiber.

kirankumar-grootan avatar kirankumar-grootan commented on June 13, 2024

@sixcolors thanks I did the same way and it works

from fiber.

Related Issues (20)

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.