From 0cc994c2b7812ff757bd74610034eb59b5ea2531 Mon Sep 17 00:00:00 2001 From: Yanislav Igonin Date: Mon, 11 Apr 2022 09:31:17 +0300 Subject: [PATCH] feat: turn rate limiter back on --- main.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index ff3fd54..9252854 100644 --- a/main.go +++ b/main.go @@ -3,17 +3,16 @@ package main import ( "log" "strconv" + "strings" _ "github.com/joho/godotenv/autoload" "github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2/middleware/compress" - "github.com/gofiber/fiber/v2/middleware/etag" + "github.com/gofiber/fiber/v2/middleware/limiter" "github.com/gofiber/fiber/v2/middleware/recover" "github.com/gofiber/template/html" - // "github.com/gofiber/fiber/v2/middleware/limiter" - "micrach/build" "micrach/config" "micrach/controllers" @@ -50,11 +49,16 @@ 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 { return c.IsFromLocal() }, - // })) + 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.Use(etag.New()) app.Static("/uploads", "./uploads") app.Static("/static", "./static")