change limiter enabling

This commit is contained in:
Yanislav Igonin 2022-05-18 10:45:53 +03:00
parent 0853d87fc3
commit 79c350c2fb

View File

@ -49,15 +49,17 @@ func main() {
app := fiber.New(fiber.Config{Views: engine}) app := fiber.New(fiber.Config{Views: engine})
app.Use(recover.New()) app.Use(recover.New())
if config.App.IsRateLimiterEnabled {
app.Use(limiter.New(limiter.Config{ app.Use(limiter.New(limiter.Config{
Next: func(c *fiber.Ctx) bool { Next: func(c *fiber.Ctx) bool {
isDev := c.IsFromLocal() isDev := c.IsFromLocal()
path := c.Path() path := c.Path()
isRequestForStatic := strings.Contains(path, "/static") || strings.Contains(path, "/uploads") || strings.Contains(path, "/captcha") isRequestForStatic := strings.Contains(path, "/static") || strings.Contains(path, "/uploads") || strings.Contains(path, "/captcha")
return (isRequestForStatic || isDev) && config.App.IsRateLimiterEnabled return isRequestForStatic || isDev
}, },
Max: 50, Max: 50,
})) }))
}
app.Use(compress.New()) app.Use(compress.New())
app.Static("/uploads", "./uploads") app.Static("/uploads", "./uploads")