fix(dashboard): don't crash backend on unknown files

This commit is contained in:
spiral 2022-11-16 05:55:40 +00:00
parent 8717f964d3
commit 85ab9c9ad9
No known key found for this signature in database
GPG Key ID: 244A11E4B0BCF40E

View File

@ -63,20 +63,21 @@ func notFoundHandler(rw http.ResponseWriter, r *http.Request) {
// lol // lol
if strings.HasSuffix(r.URL.Path, ".js") { if strings.HasSuffix(r.URL.Path, ".js") {
data, err = fs.ReadFile("dist" + r.URL.Path) data, err = fs.ReadFile("dist" + r.URL.Path)
rw.Header().Add("content-type", "application/javascript") rw.Header().Set("content-type", "application/javascript")
} else if strings.HasSuffix(r.URL.Path, ".css") { } else if strings.HasSuffix(r.URL.Path, ".css") {
data, err = fs.ReadFile("dist" + r.URL.Path) data, err = fs.ReadFile("dist" + r.URL.Path)
rw.Header().Add("content-type", "text/css") rw.Header().Set("content-type", "text/css")
} else if strings.HasSuffix(r.URL.Path, ".map") { } else if strings.HasSuffix(r.URL.Path, ".map") {
data, err = fs.ReadFile("dist" + r.URL.Path) data, err = fs.ReadFile("dist" + r.URL.Path)
} else { } else {
data, err = fs.ReadFile("dist/index.html") data, err = fs.ReadFile("dist/index.html")
rw.Header().Add("content-type", "text/html") rw.Header().Set("content-type", "text/html")
data = []byte(strings.Replace(string(data), `<!-- extra data -->`, defaultEmbed+versionJS, 1)) data = []byte(strings.Replace(string(data), `<!-- extra data -->`, defaultEmbed+versionJS, 1))
} }
if err != nil { if err != nil {
panic(err) rw.WriteHeader(http.StatusInternalServerError)
return
} }
rw.Write(data) rw.Write(data)