问题出在
c.FileFromFS("dist/index.html", http.FS(fs))
c.FileFromFS 的第一个参数是以 “index.html”结尾,c.FileFromFS 会调用net/http.FileServer,而后者,在碰到以"index.html"结尾的路径的时候,会返回 301,Location 设置成 ./,然后,wget在收到 301 后,又继续访问跳转地址 /,然后就发生循环了。
解决方案就是:
- 把
index.html 改名(不推荐)
- 直接把"index.html"去掉(从"dist/index.html"改成`"dist/")
以下是net/http.FileServer的帮助文档:
go doc net/http.FileServer
package http // import "net/http"
func FileServer(root FileSystem) Handler
FileServer returns a handler that serves HTTP requests with the contents of
the file system rooted at root.
As a special case, the returned file server redirects any request ending in
"/index.html" to the same path, without the final "index.html".
To use the operating system's file system implementation, use http.Dir:
http.Handle("/", http.FileServer(http.Dir("/tmp")))
To use an fs.FS implementation, use http.FileServerFS instead.