allowed origins moved to env
This commit is contained in:
parent
e3f893ac2d
commit
05ed7dc868
4 changed files with 24 additions and 17 deletions
1
api.env
1
api.env
|
|
@ -3,6 +3,7 @@ APP_PORT=9000
|
|||
APP_LOGLVL=Info
|
||||
APP_API_PREFIX=/api/v2
|
||||
APP_GIN_MODE=development
|
||||
APP_ALLOWED_ORIGINS=http://localhost:5173,
|
||||
|
||||
DB_HOST=
|
||||
DB_PORT=
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@ func main() {
|
|||
ApiPrefix: c.AppConf.ApiPrefix,
|
||||
GinMode: c.AppConf.GinMode,
|
||||
TokenProv: jwtProvider,
|
||||
AllowedOrigins: c.AppConf.AllowedOrigins,
|
||||
})
|
||||
log.Debug("Router handler initialized")
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package config
|
||||
|
||||
import "strings"
|
||||
|
||||
type Config struct {
|
||||
AppConf AppConfig
|
||||
DBConf DatabaseConfig
|
||||
|
|
@ -12,6 +14,7 @@ type AppConfig struct {
|
|||
LogLvl string
|
||||
ApiPrefix string
|
||||
GinMode string
|
||||
AllowedOrigins []string
|
||||
}
|
||||
|
||||
type DatabaseConfig struct {
|
||||
|
|
@ -39,6 +42,7 @@ func NewConfig() *Config {
|
|||
LogLvl: getEnv("APP_LOGLVL", ""),
|
||||
ApiPrefix: getEnv("APP_API_PREFIX", ""),
|
||||
GinMode: getEnv("APP_GIN_MODE", ""),
|
||||
AllowedOrigins: strings.Split(getEnv("APP_ALLOWED_ORIGINS", ""), ","),
|
||||
},
|
||||
|
||||
DBConf: DatabaseConfig{
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ type Deps struct {
|
|||
ApiPrefix string
|
||||
GinMode string
|
||||
TokenProv interfaces.JWTProvider
|
||||
AllowedOrigins []string
|
||||
}
|
||||
|
||||
func NewRouter(deps Deps) interfaces.Router {
|
||||
|
|
@ -39,7 +40,7 @@ func NewRouter(deps Deps) interfaces.Router {
|
|||
}
|
||||
|
||||
engine.Use(cors.New(cors.Config{
|
||||
AllowOrigins: []string{"http://localhost:5173"},
|
||||
AllowOrigins: deps.AllowedOrigins,
|
||||
AllowMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
|
||||
AllowHeaders: []string{"Origin", "Content-Type", "Authorization"},
|
||||
ExposeHeaders: []string{"Content-Length"},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue