feat: turn rate limiter back on

This commit is contained in:
Yanislav Igonin 2022-04-11 09:31:17 +03:00
parent 2d321e8833
commit 0cc994c2b7

18
main.go
View File

@ -3,17 +3,16 @@ package main
import ( import (
"log" "log"
"strconv" "strconv"
"strings"
_ "github.com/joho/godotenv/autoload" _ "github.com/joho/godotenv/autoload"
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/compress" "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/fiber/v2/middleware/recover"
"github.com/gofiber/template/html" "github.com/gofiber/template/html"
// "github.com/gofiber/fiber/v2/middleware/limiter"
"micrach/build" "micrach/build"
"micrach/config" "micrach/config"
"micrach/controllers" "micrach/controllers"
@ -50,11 +49,16 @@ func main() {
app := fiber.New(fiber.Config{Views: engine}) app := fiber.New(fiber.Config{Views: engine})
app.Use(recover.New()) app.Use(recover.New())
// app.Use(limiter.New(limiter.Config{ app.Use(limiter.New(limiter.Config{
// Next: func(c *fiber.Ctx) bool { return c.IsFromLocal() }, 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(compress.New())
app.Use(etag.New())
app.Static("/uploads", "./uploads") app.Static("/uploads", "./uploads")
app.Static("/static", "./static") app.Static("/static", "./static")