✨ Rate limiter
This commit is contained in:
parent
15c39609b8
commit
fbb670b96b
@ -1,12 +1,15 @@
|
|||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
"git.solsynth.dev/hypernet/nexus/pkg/internal/auth"
|
"git.solsynth.dev/hypernet/nexus/pkg/internal/auth"
|
||||||
"git.solsynth.dev/hypernet/nexus/pkg/internal/http/api"
|
"git.solsynth.dev/hypernet/nexus/pkg/internal/http/api"
|
||||||
"github.com/goccy/go-json"
|
"github.com/goccy/go-json"
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
"github.com/gofiber/fiber/v2/middleware/cors"
|
"github.com/gofiber/fiber/v2/middleware/cors"
|
||||||
"github.com/gofiber/fiber/v2/middleware/idempotency"
|
"github.com/gofiber/fiber/v2/middleware/idempotency"
|
||||||
|
"github.com/gofiber/fiber/v2/middleware/limiter"
|
||||||
"github.com/gofiber/fiber/v2/middleware/logger"
|
"github.com/gofiber/fiber/v2/middleware/logger"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
@ -44,6 +47,11 @@ func NewServer() *HTTPApp {
|
|||||||
}))
|
}))
|
||||||
|
|
||||||
app.Use(auth.ContextMiddleware)
|
app.Use(auth.ContextMiddleware)
|
||||||
|
app.Use(limiter.New(limiter.Config{
|
||||||
|
Max: viper.GetInt("rate_limit"),
|
||||||
|
Expiration: 60 * time.Second,
|
||||||
|
LimiterMiddleware: limiter.SlidingWindow{},
|
||||||
|
}))
|
||||||
|
|
||||||
api.MapAPIs(app)
|
api.MapAPIs(app)
|
||||||
|
|
||||||
|
@ -2,6 +2,8 @@ bind = "0.0.0.0:8001"
|
|||||||
grpc_bind = "0.0.0.0:7001"
|
grpc_bind = "0.0.0.0:7001"
|
||||||
domain = "localhost"
|
domain = "localhost"
|
||||||
|
|
||||||
|
rate_limit = 120
|
||||||
|
|
||||||
[debug]
|
[debug]
|
||||||
database = false
|
database = false
|
||||||
print_routes = false
|
print_routes = false
|
||||||
|
Reference in New Issue
Block a user