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_LOGLVL=Info
|
||||||
APP_API_PREFIX=/api/v2
|
APP_API_PREFIX=/api/v2
|
||||||
APP_GIN_MODE=development
|
APP_GIN_MODE=development
|
||||||
|
APP_ALLOWED_ORIGINS=http://localhost:5173,
|
||||||
|
|
||||||
DB_HOST=
|
DB_HOST=
|
||||||
DB_PORT=
|
DB_PORT=
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,7 @@ func main() {
|
||||||
ApiPrefix: c.AppConf.ApiPrefix,
|
ApiPrefix: c.AppConf.ApiPrefix,
|
||||||
GinMode: c.AppConf.GinMode,
|
GinMode: c.AppConf.GinMode,
|
||||||
TokenProv: jwtProvider,
|
TokenProv: jwtProvider,
|
||||||
|
AllowedOrigins: c.AppConf.AllowedOrigins,
|
||||||
})
|
})
|
||||||
log.Debug("Router handler initialized")
|
log.Debug("Router handler initialized")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
package config
|
package config
|
||||||
|
|
||||||
|
import "strings"
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
AppConf AppConfig
|
AppConf AppConfig
|
||||||
DBConf DatabaseConfig
|
DBConf DatabaseConfig
|
||||||
|
|
@ -12,6 +14,7 @@ type AppConfig struct {
|
||||||
LogLvl string
|
LogLvl string
|
||||||
ApiPrefix string
|
ApiPrefix string
|
||||||
GinMode string
|
GinMode string
|
||||||
|
AllowedOrigins []string
|
||||||
}
|
}
|
||||||
|
|
||||||
type DatabaseConfig struct {
|
type DatabaseConfig struct {
|
||||||
|
|
@ -39,6 +42,7 @@ func NewConfig() *Config {
|
||||||
LogLvl: getEnv("APP_LOGLVL", ""),
|
LogLvl: getEnv("APP_LOGLVL", ""),
|
||||||
ApiPrefix: getEnv("APP_API_PREFIX", ""),
|
ApiPrefix: getEnv("APP_API_PREFIX", ""),
|
||||||
GinMode: getEnv("APP_GIN_MODE", ""),
|
GinMode: getEnv("APP_GIN_MODE", ""),
|
||||||
|
AllowedOrigins: strings.Split(getEnv("APP_ALLOWED_ORIGINS", ""), ","),
|
||||||
},
|
},
|
||||||
|
|
||||||
DBConf: DatabaseConfig{
|
DBConf: DatabaseConfig{
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ type Deps struct {
|
||||||
ApiPrefix string
|
ApiPrefix string
|
||||||
GinMode string
|
GinMode string
|
||||||
TokenProv interfaces.JWTProvider
|
TokenProv interfaces.JWTProvider
|
||||||
|
AllowedOrigins []string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewRouter(deps Deps) interfaces.Router {
|
func NewRouter(deps Deps) interfaces.Router {
|
||||||
|
|
@ -39,7 +40,7 @@ func NewRouter(deps Deps) interfaces.Router {
|
||||||
}
|
}
|
||||||
|
|
||||||
engine.Use(cors.New(cors.Config{
|
engine.Use(cors.New(cors.Config{
|
||||||
AllowOrigins: []string{"http://localhost:5173"},
|
AllowOrigins: deps.AllowedOrigins,
|
||||||
AllowMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
|
AllowMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
|
||||||
AllowHeaders: []string{"Origin", "Content-Type", "Authorization"},
|
AllowHeaders: []string{"Origin", "Content-Type", "Authorization"},
|
||||||
ExposeHeaders: []string{"Content-Length"},
|
ExposeHeaders: []string{"Content-Length"},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue