Skip to content

Commit

Permalink
Handle case where we have an index.html that isn't included in the ur…
Browse files Browse the repository at this point in the history
…l path.

Fixes #14
  • Loading branch information
qbit committed Dec 12, 2021
1 parent 95bf60d commit 0baef71
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,16 @@ func main() {
}

if len(entries) > 0 {
if r.URL.Path == "/" {
// If we have entries, and are serving up /, check for
// index.html and redirect to that if it exists. We redirect
// because net/http handles index.html magically for FileServer
_, fErr := os.Stat(filepath.Clean(path.Join(userPath, "index.html")))
if !os.IsNotExist(fErr) {
http.Redirect(w, r, "/index.html", 301)
return
}
}
handler.fs.ServeHTTP(w, r)
} else {
l := Landing{
Expand Down Expand Up @@ -415,4 +425,4 @@ func main() {
log.Printf("Listening for HTTP on 'http://%s'", listen)
log.Fatalln(s.Serve(lis))
}
}
}

0 comments on commit 0baef71

Please sign in to comment.