fix(config): auto-detect http/https scheme for swagger

This commit is contained in:
Tiago Yamamoto 2025-12-15 13:24:37 -03:00
parent 52f31710cf
commit 1002a2ec83

View file

@ -39,12 +39,21 @@ func main() {
if apiHost == "" { if apiHost == "" {
apiHost = "localhost:8521" apiHost = "localhost:8521"
} }
// Strip protocol schemes if present to ensure clean host for Swagger
// Detect scheme from env var
schemes := []string{"http", "https"} // default to both
if strings.HasPrefix(apiHost, "https://") {
schemes = []string{"https"}
} else if strings.HasPrefix(apiHost, "http://") {
schemes = []string{"http"}
}
// Strip protocol schemes to ensure clean host for Swagger
apiHost = strings.TrimPrefix(apiHost, "http://") apiHost = strings.TrimPrefix(apiHost, "http://")
apiHost = strings.TrimPrefix(apiHost, "https://") apiHost = strings.TrimPrefix(apiHost, "https://")
docs.SwaggerInfo.Host = apiHost docs.SwaggerInfo.Host = apiHost
docs.SwaggerInfo.Schemes = []string{"http", "https"} docs.SwaggerInfo.Schemes = schemes
handler := router.NewRouter() handler := router.NewRouter()