Add swagger host/scheme env config

This commit is contained in:
Tiago Yamamoto 2025-12-21 22:16:11 -03:00
parent f71a3a320a
commit 73ebe3ec6d
3 changed files with 16 additions and 0 deletions

View file

@ -29,5 +29,11 @@ MARKETPLACE_COMMISSION=2.5
# CORS_ORIGINS=https://app.saveinmed.com,https://admin.saveinmed.com,http://localhost:3000 # CORS_ORIGINS=https://app.saveinmed.com,https://admin.saveinmed.com,http://localhost:3000
CORS_ORIGINS=* CORS_ORIGINS=*
# Swagger Configuration
# Host without scheme (ex: localhost:8214 or api.saveinmed.com)
SWAGGER_HOST=localhost:8214
# Comma-separated list of schemes shown in Swagger UI selector
SWAGGER_SCHEMES=http,https
# Testing (Optional) # Testing (Optional)
# SKIP_DB_TEST=1 # SKIP_DB_TEST=1

View file

@ -30,6 +30,12 @@ func main() {
// swagger metadata overrides // swagger metadata overrides
docs.SwaggerInfo.Title = cfg.AppName docs.SwaggerInfo.Title = cfg.AppName
docs.SwaggerInfo.BasePath = "/" docs.SwaggerInfo.BasePath = "/"
if cfg.SwaggerHost != "" {
docs.SwaggerInfo.Host = cfg.SwaggerHost
}
if len(cfg.SwaggerSchemes) > 0 {
docs.SwaggerInfo.Schemes = cfg.SwaggerSchemes
}
srv, err := server.New(cfg) srv, err := server.New(cfg)
if err != nil { if err != nil {

View file

@ -22,6 +22,8 @@ type Config struct {
JWTExpiresIn time.Duration JWTExpiresIn time.Duration
PasswordPepper string PasswordPepper string
CORSOrigins []string CORSOrigins []string
SwaggerHost string
SwaggerSchemes []string
} }
// Load reads configuration from environment variables and applies sane defaults // Load reads configuration from environment variables and applies sane defaults
@ -40,6 +42,8 @@ func Load() Config {
JWTExpiresIn: getEnvDuration("JWT_EXPIRES_IN", 24*time.Hour), JWTExpiresIn: getEnvDuration("JWT_EXPIRES_IN", 24*time.Hour),
PasswordPepper: getEnv("PASSWORD_PEPPER", ""), PasswordPepper: getEnv("PASSWORD_PEPPER", ""),
CORSOrigins: getEnvStringSlice("CORS_ORIGINS", []string{"*"}), CORSOrigins: getEnvStringSlice("CORS_ORIGINS", []string{"*"}),
SwaggerHost: getEnv("SWAGGER_HOST", ""),
SwaggerSchemes: getEnvStringSlice("SWAGGER_SCHEMES", []string{"http"}),
} }
return cfg return cfg