I'm using a third-party router (httprouter) on Google App Engine and would like to serve static files from root.
Because of App Engine, I need to attach the third-party router to the DefaultServeMux
on /
:
router := httprouter.New()
// Doesn't work, duplicated "/".
http.Handle("/", http.FileServer(http.Dir("public")))
// Needed because of App Engine.
http.Handle("/", router)
The problem is this duplicates the /
pattern and panics with "multiple registrations for /"
How can I serve files, especially index.html
from root and use a third-party router?
If you serve static files at
/
then you can't serve any other paths as per https://github.com/julienschmidt/httprouter/issues/7#issuecomment-45725482You should use Go to serve a template at the application root and static files (CSS, JS, etc) at a sub path: