fix(dashboard): don't crash backend on unknown files
This commit is contained in:
parent
8717f964d3
commit
85ab9c9ad9
@ -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)
|
||||||
|
Loading…
Reference in New Issue
Block a user