diff --git a/ioc/apps/apidoc/restful/swagger.go b/ioc/apps/apidoc/restful/swagger.go index 96b4cd7..fba3b68 100644 --- a/ioc/apps/apidoc/restful/swagger.go +++ b/ioc/apps/apidoc/restful/swagger.go @@ -2,11 +2,13 @@ package restful import ( "fmt" + "path/filepath" restfulspec "github.com/emicklei/go-restful-openapi/v2" "github.com/emicklei/go-restful/v3" "github.com/infraboard/mcube/v2/ioc" "github.com/infraboard/mcube/v2/ioc/apps/apidoc" + "github.com/infraboard/mcube/v2/ioc/config/application" "github.com/infraboard/mcube/v2/ioc/config/gorestful" "github.com/infraboard/mcube/v2/ioc/config/http" "github.com/infraboard/mcube/v2/ioc/config/log" @@ -50,11 +52,19 @@ func (h *SwaggerApiDoc) Meta() ioc.ObjectMeta { } func (h *SwaggerApiDoc) ApiDocPath() string { - return fmt.Sprintf("%s%s", http.Get().ApiObjectAddr(h), h.JsonPath) + if application.Get().Domain != "" { + return application.Get().Endpoint() + filepath.Join(http.Get().ApiObjectPathPrefix(h), h.JsonPath) + } + + return http.Get().ApiObjectAddr(h) + h.JsonPath } func (h *SwaggerApiDoc) ApiUIPath() string { - return fmt.Sprintf("%s%s", http.Get().ApiObjectAddr(h), h.UIPath) + if application.Get().Domain != "" { + return application.Get().Endpoint() + filepath.Join(http.Get().ApiObjectPathPrefix(h), h.UIPath) + } + + return http.Get().ApiObjectAddr(h) + h.UIPath } func (h *SwaggerApiDoc) Registry() { @@ -87,7 +97,7 @@ func (h *SwaggerApiDoc) SwaggerUI(r *restful.Request, w *restful.Response) { // API Doc func (h *SwaggerApiDoc) SwaggerDocConfig() restfulspec.Config { return restfulspec.Config{ - Host: http.Get().Host, + Host: http.Get().Addr(), WebServices: restful.RegisteredWebServices(), APIPath: http.Get().ApiObjectPathPrefix(h), PostBuildSwaggerObjectHandler: http.Get().SwagerDocs, diff --git a/ioc/apps/apidoc/swaggo/swagger.go b/ioc/apps/apidoc/swaggo/swagger.go index 3f6660d..c1ab5f6 100644 --- a/ioc/apps/apidoc/swaggo/swagger.go +++ b/ioc/apps/apidoc/swaggo/swagger.go @@ -2,10 +2,12 @@ package swaggo import ( "fmt" + "path/filepath" "github.com/gin-gonic/gin" "github.com/infraboard/mcube/v2/ioc" "github.com/infraboard/mcube/v2/ioc/apps/apidoc" + "github.com/infraboard/mcube/v2/ioc/config/application" ioc_gin "github.com/infraboard/mcube/v2/ioc/config/gin" "github.com/infraboard/mcube/v2/ioc/config/http" "github.com/infraboard/mcube/v2/ioc/config/log" @@ -60,11 +62,19 @@ func (h *SwaggerApiDoc) Registry() { } func (h *SwaggerApiDoc) ApiDocPath() string { - return fmt.Sprintf("%s%s", http.Get().ApiObjectAddr(h), h.JsonPath) + if application.Get().Domain != "" { + return application.Get().Endpoint() + filepath.Join(http.Get().ApiObjectPathPrefix(h), h.JsonPath) + } + + return http.Get().ApiObjectAddr(h) + h.JsonPath } func (h *SwaggerApiDoc) ApiUIPath() string { - return fmt.Sprintf("%s%s", http.Get().ApiObjectAddr(h), h.UIPath) + if application.Get().Domain != "" { + return application.Get().Endpoint() + filepath.Join(http.Get().ApiObjectPathPrefix(h), h.UIPath) + } + + return http.Get().ApiObjectAddr(h) + h.UIPath } func (h *SwaggerApiDoc) SwaggerJson(ctx *gin.Context) { diff --git a/ioc/config/application/application.go b/ioc/config/application/application.go index cc63a27..352e436 100644 --- a/ioc/config/application/application.go +++ b/ioc/config/application/application.go @@ -15,7 +15,7 @@ func init() { var defaultConfig = &Application{ AppName: "", AppGroup: "default", - Domain: "localhost", + Domain: "", Security: false, EncryptKey: "defualt app encrypt key", CipherPrefix: "@ciphered@", @@ -49,7 +49,7 @@ func (i *Application) GetAppName() string { } func (i *Application) IsInternalIP() bool { - return i.Domain != "localhost" + return i.Domain != "localhost" && i.Domain != "" && i.Domain != "127.0.0.1" } func (i *Application) Endpoint() string {