feat: frontend use router

This commit is contained in:
Samuel N Cui
2022-12-13 20:02:29 +08:00
parent b9355ad892
commit cda9244e8e
10 changed files with 167 additions and 62 deletions
+6 -7
View File
@@ -96,15 +96,14 @@ func main() {
fs := http.FileServer(http.Dir("./frontend/assets"))
mux.Handle("/assets/", http.StripPrefix("/assets/", fs))
indexBuf, err := ioutil.ReadFile("./frontend/index.html")
if err != nil {
panic(err)
}
indexBuf = bytes.ReplaceAll(indexBuf, []byte("%%API_BASE%%"), []byte(fmt.Sprintf("%s/services", conf.Domain)))
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
indexBuf, err := ioutil.ReadFile("./frontend/index.html")
if err != nil {
panic(err)
}
w.Header().Set("Content-Type", "text/html; charset=utf-8")
w.Write(indexBuf)
w.Write(bytes.ReplaceAll(indexBuf, []byte("%%API_BASE%%"), []byte(fmt.Sprintf("%s/services", conf.Domain))))
})
srv := &http.Server{