aboutsummaryrefslogtreecommitdiff
path: root/router/router.go
diff options
context:
space:
mode:
Diffstat (limited to 'router/router.go')
-rw-r--r--router/router.go13
1 files changed, 12 insertions, 1 deletions
diff --git a/router/router.go b/router/router.go
index c53cea4..7845b41 100644
--- a/router/router.go
+++ b/router/router.go
@@ -3,11 +3,22 @@ package router
import (
"paperchan.club/controllers"
"github.com/gofiber/fiber/v2"
+ "github.com/gofiber/fiber/v2/middleware/limiter"
+ "time"
+ "strings"
)
func SetRoutes(app *fiber.App) {
app.Get("/", controllers.ThreadList)
app.Get("/thread/:id", controllers.Thread)
- app.Post("/api/post", controllers.Publish)
+ app.Post("/api/post", rateLimiter, controllers.Publish)
app.Delete("/api/post", controllers.Delete)
}
+
+var rateLimiter = limiter.New(limiter.Config{
+ Max: 5,
+ Expiration: 10*time.Minute,
+ KeyGenerator: func(c *fiber.Ctx) string {
+ return c.IP()+" "+strings.Join(c.IPs()," ")
+ },
+})