Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting 404 for CSS and JS files #225

Open
applejag opened this issue Aug 4, 2022 · 1 comment
Open

Getting 404 for CSS and JS files #225

applejag opened this issue Aug 4, 2022 · 1 comment

Comments

@applejag
Copy link

applejag commented Aug 4, 2022

The CSS & JS files all respond with 404. Even using the example from the README.md I still get the same results.

gin-swagger/README.md

Lines 99 to 136 in b9e926c

package main
import (
"github.com/gin-gonic/gin"
docs "github.com/go-project-name/docs"
swaggerfiles "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger"
"net/http"
)
// @BasePath /api/v1
// PingExample godoc
// @Summary ping example
// @Schemes
// @Description do ping
// @Tags example
// @Accept json
// @Produce json
// @Success 200 {string} Helloworld
// @Router /example/helloworld [get]
func Helloworld(g *gin.Context) {
g.JSON(http.StatusOK,"helloworld")
}
func main() {
r := gin.Default()
docs.SwaggerInfo.BasePath = "/api/v1"
v1 := r.Group("/api/v1")
{
eg := v1.Group("/example")
{
eg.GET("/helloworld",Helloworld)
}
}
r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerfiles.Handler))
r.Run(":8080")
}

[GIN-debug] [WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.

[GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.
 - using env:   export GIN_MODE=release
 - using code:  gin.SetMode(gin.ReleaseMode)

[GIN-debug] GET    /api/v1/example/helloworld --> main.Helloworld (3 handlers)
[GIN-debug] GET    /swagger/*any             --> github.com/swaggo/gin-swagger.CustomWrapHandler.func1 (3 handlers)
[GIN-debug] [WARNING] You trusted all proxies, this is NOT safe. We recommend you to set a value.
Please check https://pkg.go.dev/github.com/gin-gonic/gin#readme-don-t-trust-all-proxies for details.
[GIN-debug] Listening and serving HTTP on :8080
[GIN] 2022/08/04 - 12:43:51 | 200 |     149.986µs |       127.0.0.1 | GET      "/swagger/index.html"
[GIN] 2022/08/04 - 12:43:51 | 404 |      14.294µs |       127.0.0.1 | GET      "/swagger/swagger-ui-bundle.js"
[GIN] 2022/08/04 - 12:43:51 | 404 |      20.702µs |       127.0.0.1 | GET      "/swagger/swagger-ui-standalone-preset.js"
[GIN] 2022/08/04 - 12:43:51 | 404 |       6.681µs |       127.0.0.1 | GET      "/swagger/swagger-ui.css"

Maybe related: swaggo/http-swagger#10, don't know if the issue is in this codebase or in some dependency, but it's not working here as well.

@bebetterLWJ
Copy link

you can get in ginswagger.WrapHandler -> CustomWrapHandler
you can see once.Do(func() {
handler.Prefix = matches[1]
})
and handler.ServeHTTP(c.Writer, c.Request), that means when the first request url is where .js、.css in, so you have to use the same url as the first request url or replace /swagger/*any with a specific route

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants