httprouter icon indicating copy to clipboard operation
httprouter copied to clipboard

ServeFiles not able to serve static files

Open ta1bbty opened this issue 4 years ago • 2 comments

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.

ta1bbty avatar Aug 30 '21 19:08 ta1bbty

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

go-aegian avatar Dec 10 '21 20:12 go-aegian

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

dolmen avatar Apr 26 '22 15:04 dolmen