Skip to content

Commit

Permalink
Fix home page index.html load
Browse files Browse the repository at this point in the history
  • Loading branch information
SmilyOrg committed Jul 9, 2022
1 parent 1235266 commit 4431147
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"io/ioutil"
"math"
"mime"
"path"
"path/filepath"
"regexp"
"sort"
Expand Down Expand Up @@ -913,6 +914,17 @@ func CacheControl() func(next http.Handler) http.Handler {
}
}

func IndexHTML() func(next http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if strings.HasSuffix(r.URL.Path, "/") || len(r.URL.Path) == 0 {
r.URL.Path = path.Join(r.URL.Path, "index.html")
}
next.ServeHTTP(w, r)
})
}
}

func main() {

startupTime = time.Now()
Expand Down Expand Up @@ -1052,6 +1064,7 @@ func main() {

r.Route("/", func(r chi.Router) {
r.Use(CacheControl())
r.Use(IndexHTML())
r.Handle("/*", server)
})
msg = fmt.Sprintf("ui at %v, %s", addr, msg)
Expand Down

0 comments on commit 4431147

Please sign in to comment.