fix(config): auto-detect http/https scheme for swagger
This commit is contained in:
parent
52f31710cf
commit
1002a2ec83
1 changed files with 11 additions and 2 deletions
|
|
@ -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()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue