Handle case where we have an index.html that isn't included in the url path.
Fixes #14
This commit is contained in:
parent
95bf60da41
commit
0baef712b2
12
main.go
12
main.go
@ -372,6 +372,16 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(entries) > 0 {
|
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)
|
handler.fs.ServeHTTP(w, r)
|
||||||
} else {
|
} else {
|
||||||
l := Landing{
|
l := Landing{
|
||||||
@ -415,4 +425,4 @@ func main() {
|
|||||||
log.Printf("Listening for HTTP on 'http://%s'", listen)
|
log.Printf("Listening for HTTP on 'http://%s'", listen)
|
||||||
log.Fatalln(s.Serve(lis))
|
log.Fatalln(s.Serve(lis))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user