forked from ebhomengo/niki
				
			feat: add CORS middleware configuration with custom allowed origins(#154)
This commit is contained in:
		
							parent
							
								
									9ddcdd7a82
								
							
						
					
					
						commit
						2c3124ee2c
					
				|  | @ -10,7 +10,12 @@ import ( | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| type HTTPServer struct { | 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 { | type Config struct { | ||||||
|  |  | ||||||
|  | @ -67,6 +67,9 @@ func (s Server) Serve() { | ||||||
| func (s Server) RegisterRoutes() { | func (s Server) RegisterRoutes() { | ||||||
| 	s.Router.Use(middleware.RequestID()) | 	s.Router.Use(middleware.RequestID()) | ||||||
| 	s.Router.Use(middleware.Recover()) | 	s.Router.Use(middleware.Recover()) | ||||||
|  | 	s.Router.Use(middleware.CORSWithConfig(middleware.CORSConfig{ | ||||||
|  | 		AllowOrigins: s.config.HTTPServer.Cors.AllowOrigins, | ||||||
|  | 	})) | ||||||
| 	registerSwagger(s.Router) | 	registerSwagger(s.Router) | ||||||
| 
 | 
 | ||||||
| 	// Routes
 | 	// Routes
 | ||||||
|  |  | ||||||
|  | @ -3,6 +3,9 @@ type: yml | ||||||
| 
 | 
 | ||||||
| http_server: | http_server: | ||||||
|   port: 1313 |   port: 1313 | ||||||
|  |   cors: | ||||||
|  |     allow_origins: | ||||||
|  |       - "*" | ||||||
| 
 | 
 | ||||||
| benefactor_service: | benefactor_service: | ||||||
|   length_of_otp_code: 5 |   length_of_otp_code: 5 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue