Merge pull request #23 from rede5/codex/add-url-selection-from-env-file
Add Swagger host and schemes env config
This commit is contained in:
commit
e162ef04a5
3 changed files with 16 additions and 0 deletions
|
|
@ -29,5 +29,11 @@ MARKETPLACE_COMMISSION=2.5
|
|||
# CORS_ORIGINS=https://app.saveinmed.com,https://admin.saveinmed.com,http://localhost:3000
|
||||
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)
|
||||
# SKIP_DB_TEST=1
|
||||
|
|
|
|||
|
|
@ -30,6 +30,12 @@ func main() {
|
|||
// swagger metadata overrides
|
||||
docs.SwaggerInfo.Title = cfg.AppName
|
||||
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)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@ type Config struct {
|
|||
JWTExpiresIn time.Duration
|
||||
PasswordPepper string
|
||||
CORSOrigins []string
|
||||
SwaggerHost string
|
||||
SwaggerSchemes []string
|
||||
}
|
||||
|
||||
// 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),
|
||||
PasswordPepper: getEnv("PASSWORD_PEPPER", ""),
|
||||
CORSOrigins: getEnvStringSlice("CORS_ORIGINS", []string{"*"}),
|
||||
SwaggerHost: getEnv("SWAGGER_HOST", ""),
|
||||
SwaggerSchemes: getEnvStringSlice("SWAGGER_SCHEMES", []string{"http"}),
|
||||
}
|
||||
|
||||
return cfg
|
||||
|
|
|
|||
Loading…
Reference in a new issue