forked from ebhomengo/niki
1
0
Fork 0

Merge pull request 'feat: add CORS middleware configuration with custom allowed origins(#154)' (#155) from stage/erfan/add-cors-configuration into develop

Reviewed-on: ebhomengo/niki#155
This commit is contained in:
hossein 2024-09-11 05:58:26 +00:00
commit 083327472c
3 changed files with 12 additions and 1 deletions

View File

@ -11,6 +11,11 @@ import (
type HTTPServer struct {
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