From 85ab9c9ad91aa04c2cee93eb5a0b39d6d560aa2c Mon Sep 17 00:00:00 2001 From: spiral Date: Wed, 16 Nov 2022 05:55:40 +0000 Subject: [PATCH] fix(dashboard): don't crash backend on unknown files --- dashboard/main.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/dashboard/main.go b/dashboard/main.go index 311bb7cb..894a1dbf 100644 --- a/dashboard/main.go +++ b/dashboard/main.go @@ -63,20 +63,21 @@ func notFoundHandler(rw http.ResponseWriter, r *http.Request) { // lol if strings.HasSuffix(r.URL.Path, ".js") { 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") { 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") { data, err = fs.ReadFile("dist" + r.URL.Path) } else { 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), ``, defaultEmbed+versionJS, 1)) } if err != nil { - panic(err) + rw.WriteHeader(http.StatusInternalServerError) + return } rw.Write(data)