fixed problem with '/' causing loading issues with application
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"net/http"
|
||||
"net/http/httputil"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
chimiddleware "github.com/go-chi/chi/v5/middleware"
|
||||
@@ -232,7 +233,12 @@ func mustParseURL(raw string) *url.URL {
|
||||
func spaHandler(staticFiles fs.FS) http.Handler {
|
||||
fileServer := http.FileServer(http.FS(staticFiles))
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
_, err := staticFiles.Open(r.URL.Path)
|
||||
// fs.FS paths must not have a leading slash.
|
||||
path := strings.TrimPrefix(r.URL.Path, "/")
|
||||
if path == "" {
|
||||
path = "."
|
||||
}
|
||||
_, err := staticFiles.Open(path)
|
||||
if err != nil {
|
||||
r.URL.Path = "/"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user