fix: strip /swagger prefix for swaggerFiles.Handler path resolution
Some checks failed
CI / Build & Test (push) Failing after 42s
Some checks failed
CI / Build & Test (push) Failing after 42s
This commit is contained in:
parent
98256f1f54
commit
d26f5962ed
@ -16,7 +16,15 @@ import (
|
|||||||
// branding CSS injected into swagger-ui.css.
|
// branding CSS injected into swagger-ui.css.
|
||||||
func SwaggerHandler() gin.HandlerFunc {
|
func SwaggerHandler() gin.HandlerFunc {
|
||||||
return func(c *gin.Context) {
|
return func(c *gin.Context) {
|
||||||
isCSS := strings.HasSuffix(c.Request.URL.Path, "swagger-ui.css")
|
rawPath := c.Request.URL.Path
|
||||||
|
relPath := strings.TrimPrefix(rawPath, "/swagger")
|
||||||
|
if relPath == "" || relPath == "/" {
|
||||||
|
relPath = "/index.html"
|
||||||
|
}
|
||||||
|
c.Request.URL.Path = relPath
|
||||||
|
defer func() { c.Request.URL.Path = rawPath }()
|
||||||
|
|
||||||
|
isCSS := strings.HasSuffix(relPath, "swagger-ui.css")
|
||||||
|
|
||||||
underlying := c.Writer
|
underlying := c.Writer
|
||||||
crw := &captureResponseWriter{
|
crw := &captureResponseWriter{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user