Correctly fill swagger host field
This commit is contained in:
parent
82cb2e384a
commit
19811dafb2
|
|
@ -5,11 +5,13 @@ import (
|
|||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gobuffalo/packr"
|
||||
"github.com/gotify/location"
|
||||
)
|
||||
|
||||
// Serve serves the documentation.
|
||||
func Serve(ctx *gin.Context) {
|
||||
ctx.Writer.WriteString(get(ctx.Request.URL.Host))
|
||||
url := location.Get(ctx)
|
||||
ctx.Writer.WriteString(get(url.Host))
|
||||
}
|
||||
|
||||
func get(host string) string {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package docs
|
|||
|
||||
import (
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"testing"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
|
@ -13,11 +14,16 @@ func TestServe(t *testing.T) {
|
|||
mode.Set(mode.TestDev)
|
||||
recorder := httptest.NewRecorder()
|
||||
ctx, _ := gin.CreateTestContext(recorder)
|
||||
withURL(ctx, "http", "example.com")
|
||||
|
||||
ctx.Request = httptest.NewRequest("GET", "/swagger", nil)
|
||||
ctx.Request.URL.Host = "localhost"
|
||||
|
||||
Serve(ctx)
|
||||
|
||||
content := recorder.Body.String()
|
||||
assert.NotEmpty(t, content)
|
||||
}
|
||||
|
||||
func withURL(ctx *gin.Context, scheme, host string) {
|
||||
ctx.Set("location", &url.URL{Scheme: scheme, Host: host})
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue