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=
|
||||
|
|
|
|||
|
|
@ -52,9 +52,10 @@ func main() {
|
|||
|
||||
//deps providers
|
||||
routerHandler := router.NewRouter(router.Deps{
|
||||
ApiPrefix: c.AppConf.ApiPrefix,
|
||||
GinMode: c.AppConf.GinMode,
|
||||
TokenProv: jwtProvider,
|
||||
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
|
||||
|
|
@ -7,11 +9,12 @@ type Config struct {
|
|||
}
|
||||
|
||||
type AppConfig struct {
|
||||
Host string
|
||||
Port string
|
||||
LogLvl string
|
||||
ApiPrefix string
|
||||
GinMode string
|
||||
Host string
|
||||
Port string
|
||||
LogLvl string
|
||||
ApiPrefix string
|
||||
GinMode string
|
||||
AllowedOrigins []string
|
||||
}
|
||||
|
||||
type DatabaseConfig struct {
|
||||
|
|
@ -34,11 +37,12 @@ type JWTConfig struct {
|
|||
func NewConfig() *Config {
|
||||
return &Config{
|
||||
AppConf: AppConfig{
|
||||
Host: getEnv("APP_HOST", ""),
|
||||
Port: getEnv("APP_PORT", ""),
|
||||
LogLvl: getEnv("APP_LOGLVL", ""),
|
||||
ApiPrefix: getEnv("APP_API_PREFIX", ""),
|
||||
GinMode: getEnv("APP_GIN_MODE", ""),
|
||||
Host: getEnv("APP_HOST", ""),
|
||||
Port: getEnv("APP_PORT", ""),
|
||||
LogLvl: getEnv("APP_LOGLVL", ""),
|
||||
ApiPrefix: getEnv("APP_API_PREFIX", ""),
|
||||
GinMode: getEnv("APP_GIN_MODE", ""),
|
||||
AllowedOrigins: strings.Split(getEnv("APP_ALLOWED_ORIGINS", ""), ","),
|
||||
},
|
||||
|
||||
DBConf: DatabaseConfig{
|
||||
|
|
|
|||
|
|
@ -21,9 +21,10 @@ type router struct {
|
|||
}
|
||||
|
||||
type Deps struct {
|
||||
ApiPrefix string
|
||||
GinMode string
|
||||
TokenProv interfaces.JWTProvider
|
||||
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