我有以下代碼:配菜子目錄[GoLang]
r := mux.NewRouter()
r.Handle("/", http.FileServer(http.Dir("./frontend/build/")))
r.Handle("/static", http.FileServer(http.Dir("./frontend/build/static/")))
r.PathPrefix("/api").Handler(auth)
/api
被認爲是安全的。如果用戶點擊/
,我希望他們查看PROJECTDIR/frontend
目錄中的index.html
。
的前端目錄看起來從/static
像
frontend
/build
index.html
/static
/js
/css
/media
中的index.html加載所有內容。不管我怎麼配置這個,當我訪問localhost:3000
時,我可以得到index.html
,但是在/static
下的所有東西都是404'd。
我怎麼配置這個不正確?
參見[此類似QA] (https://stackoverflow.com/questions/43601359/how-do-i-serve-css-and-js-in-go-lang) – putu