我有以下代码来为Reaction构建应用程序提供服务:
package main
import (
"fmt"
"log"
"net/http"
"time"
)
func main() {
r := http.NewServeMux()
r.HandleFunc(`^/`, index)
buildHandler := http.FileServer(http.Dir("build"))
r.Handle("/", buildHandler)
srv := &http.Server{
Handler: r,
Addr: ":5000",
WriteTimeout: 15 * time.Second,
ReadTimeout: 15 * time.Second,
}
fmt.Println("Server started on PORT 5000")
log.Fatal(srv.ListenAndServe())
}
func index(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "build/index.html")
}
文件夹 struct 如下所示:
但在刷新或try 直接转到PATH时,未找到404.我怎么才能让它go 到想要的路径,而不是go 404?