Skip to content
New issue

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

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

Already on GitHub? # to your account

Root static resource router not supported #2537

Closed
oyoungs opened this issue Oct 21, 2020 · 2 comments · Fixed by #2663
Closed

Root static resource router not supported #2537

oyoungs opened this issue Oct 21, 2020 · 2 comments · Fixed by #2663

Comments

@oyoungs
Copy link

oyoungs commented Oct 21, 2020

After I registered other routers, when I want to register the static resources router to the path "/", it told me "CONFLICTS"

My code:

func main() {
        router := gin.Default()

	router.Use(gin.Logger())

	router.Use(gin.Recovery())

	router.StaticFS("/", http.Dir("public"))

	v1 := router.Group("/api/v1")

	{
		task := v1.Group("/task")

		api.NewTaskApi(task)

	}

	router.Run(":3408")
}

errors like that:

panic: '/api/v1/task/' in new path '/api/v1/task/' conflicts with existing wildcard '/*filepath' in existing prefix '/*filepath'
@athe0i
Copy link

athe0i commented Oct 21, 2020

@oyoungs router.StaticFS registers param path into the router with /*filepath which creates conflict with everything else in the root path. my suggestion would be to use something like router.StaticFS("/public", http.Dir("public")) . static and param paths collision is known issue - #2016

@oyoungs
Copy link
Author

oyoungs commented Oct 21, 2020

I tried, but in the front-end file "index.html", all request urls are based on the path "/":

├── asset-manifest.json
├── favicon.ico
├── index.html
├── manifest.json
├── service-worker.js
└── static
    ├── css
    │   └── main.6d1949a3.css
    ├── js
    │   ├── 0.81fb3f90.chunk.js
    │   ├── 1.b9d9e99d.chunk.js
    │   └── main.86df6cbc.js

So my static resource path must be "/", else it will tell me "404 Not Found"

But if I use the http.ServeMux, the static resource path "/" and the api router "/api/v1" are compatible( '/api/v1' has higher priority )

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
2 participants