Fix base_path for integration with Hass

This commit is contained in:
Alexey Khit
2022-09-16 14:19:23 +03:00
parent 63b9639e86
commit 71e1c840a7
7 changed files with 22 additions and 15 deletions
+4 -4
View File
@@ -14,13 +14,13 @@ func initStatic(staticDir string) {
root = http.FS(www.Static)
}
base := len(basePath)
fileServer := http.FileServer(root)
HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
if basePath != "" {
r.URL.Path = r.URL.Path[len(basePath):]
HandleFunc("", func(w http.ResponseWriter, r *http.Request) {
if base > 0 {
r.URL.Path = r.URL.Path[base:]
}
fileServer.ServeHTTP(w, r)
})
}