1
我的项目结构如下:文件服务器()总是返回的index.html
/rootfolder
index.html
main.js
main.go
我试图通过文件服务器(),它总是返回index.html作为响应提供静态的JavaScript文件而不是main.js
在main.go:
serveFile := http.StripPrefix("/res/", http.FileServer(http.Dir(".")))
http.HandleFunc("/", indexHandler)
http.Handle("/res", serveFile)
http.ListenAndServe(":8080", nil)
里面的index.html main.js引用如下:
<script src="/res/main.js"></script>
从我的浏览器的网络选项卡,看来文件服务器()总是返回index.html文件为/res/main.js