julienschmidt / httprouter

A high performance HTTP request router that scales well
https://pkg.go.dev/github.com/julienschmidt/httprouter
BSD 3-Clause "New" or "Revised" License
16.56k stars 1.47k forks source link

ServeFiles not able to serve static files #337

Open ta1bbty opened 3 years ago

ta1bbty commented 3 years ago

Hi @julienschmidt

Thanks for the awesome library.

I am trying to host static files along with the API .

This is how I am doing this.

r.HandlerFunc("GET", "/:username", handler.Get)
r.HandlerFunc("GET", "/:username/:todo", handler.Todo)

r.ServeFiles("/login/*filepath", http.Dir("templates"))

I get the error : panic: 'login' in new path '/login/*filepath' conflicts with existing wildcard ':username' in existing prefix '/:username'

On searching through the issues, I found this #183

Is it due to this 🤔

Thanks.

go-aegian commented 2 years ago

I did review your question and while waiting on my branch to see if it apt for merging to here. You can check out this branch with your problem. What I suggested in the example is if you can prepend the handlers with "user/:username" & "/user/:username/:todo" as shown in the example files here

https://github.com/sainzg/httprouter/commit/c0fbccf698543dc30d3bc0eb2007d436394a5459

dolmen commented 2 years ago

Please rename this issue because it seems it is not specific to ServeFiles, but more to a path conflict.