Closed nathanhack closed 4 years ago
I don't know if it happens in older versions but in go1.13. The example middlewrapper ends up in a loop of redirecting.
The middleware basically adds "index.html" to "/" which is fine but it will eventually be sent to http.serveFile() which does the following:
if strings.HasSuffix(r.URL.Path, indexPage) { localRedirect(w, r, "./") return }
That localRedirect sends it back to the beginning, and it just loops over and over.
I was able to get it working by serving the file directly in the middleware:
func handleIndexPage(h http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if strings.HasSuffix(r.URL.Path, "/") { http.ServeFile(w, r, "./index.html") return } h.ServeHTTP(w, r) }) }
I've fixed the README to give separate working examples, both for full directory browsing and for just index.html handling.
I don't know if it happens in older versions but in go1.13. The example middlewrapper ends up in a loop of redirecting.
The middleware basically adds "index.html" to "/" which is fine but it will eventually be sent to http.serveFile() which does the following:
That localRedirect sends it back to the beginning, and it just loops over and over.
I was able to get it working by serving the file directly in the middleware: