forked from ebhomengo/niki
1
0
Fork 0

feat: add CORS middleware configuration with custom allowed origins(#154)

This commit is contained in:
Erfan Mohammadi 2024-09-08 13:34:06 +03:30
parent 9ddcdd7a82
commit 2c3124ee2c
3 changed files with 12 additions and 1 deletions

View File

@ -10,7 +10,12 @@ import (
)
type HTTPServer struct {
Port int `koanf:"port"`
Port int `koanf:"port"`
Cors Cors `koanf:"cors"`
}
type Cors struct {
AllowOrigins []string `koanf:"allow_origins"`
}
type Config struct {

View File

@ -67,6 +67,9 @@ func (s Server) Serve() {
func (s Server) RegisterRoutes() {
s.Router.Use(middleware.RequestID())
s.Router.Use(middleware.Recover())
s.Router.Use(middleware.CORSWithConfig(middleware.CORSConfig{
AllowOrigins: s.config.HTTPServer.Cors.AllowOrigins,
}))
registerSwagger(s.Router)
// Routes

View File

@ -3,6 +3,9 @@ type: yml
http_server:
port: 1313
cors:
allow_origins:
- "*"
benefactor_service:
length_of_otp_code: 5