From 79c350c2fba0abbc54e42c40e4e508e45db7cb49 Mon Sep 17 00:00:00 2001 From: Yanislav Igonin Date: Wed, 18 May 2022 10:45:53 +0300 Subject: [PATCH] change limiter enabling --- main.go | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/main.go b/main.go index ff3a06e..8645a77 100644 --- a/main.go +++ b/main.go @@ -49,15 +49,17 @@ func main() { app := fiber.New(fiber.Config{Views: engine}) app.Use(recover.New()) - app.Use(limiter.New(limiter.Config{ - Next: func(c *fiber.Ctx) bool { - isDev := c.IsFromLocal() - path := c.Path() - isRequestForStatic := strings.Contains(path, "/static") || strings.Contains(path, "/uploads") || strings.Contains(path, "/captcha") - return (isRequestForStatic || isDev) && config.App.IsRateLimiterEnabled - }, - Max: 50, - })) + if config.App.IsRateLimiterEnabled { + app.Use(limiter.New(limiter.Config{ + Next: func(c *fiber.Ctx) bool { + isDev := c.IsFromLocal() + path := c.Path() + isRequestForStatic := strings.Contains(path, "/static") || strings.Contains(path, "/uploads") || strings.Contains(path, "/captcha") + return isRequestForStatic || isDev + }, + Max: 50, + })) + } app.Use(compress.New()) app.Static("/uploads", "./uploads")