julienschmidt/httprouter

Serving static files

packetq opened this issue · 1 comments

Hi,

I'm trying to get httprouter to serve static files. I have used the following

router.NotFound = http.FileServer(http.Dir("static"))

This works fine for files that are not index.html. I get a 301 error on index.html. How do I handle this case?

Thanks,
-G

Do you mean index.html (path /index.html) or the path /, which should automatically serve the index.html?

If you mean the latter, just add it manually. Something like:

func Index(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
	http.ServeFile(w, r, "static/index.html")
}

...

`router.GET("/", Index)`