api: use webui.ServeSPA in NotFound handler instead of buggy inline logic
This commit is contained in:
+1
-11
@@ -81,17 +81,7 @@ func NewServer(cfg *config.Config, db *sql.DB, engine *syncengine.Engine) *Serve
|
|||||||
}))
|
}))
|
||||||
|
|
||||||
r.NotFound(func(w http.ResponseWriter, r *http.Request) {
|
r.NotFound(func(w http.ResponseWriter, r *http.Request) {
|
||||||
if _, ok := webui.DistFS.Open("dist" + r.URL.Path); ok == nil {
|
webui.ServeSPA().ServeHTTP(w, r)
|
||||||
http.FileServer(http.FS(webui.DistFS)).ServeHTTP(w, r)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
data, err := webui.DistFS.ReadFile("dist/index.html")
|
|
||||||
if err != nil {
|
|
||||||
http.Error(w, "not found", http.StatusNotFound)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
w.Header().Set("Content-Type", "text/html")
|
|
||||||
w.Write(data)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
return s
|
return s
|
||||||
|
|||||||
Reference in New Issue
Block a user