go-chi fileserver示例后端带有vuejs frontend带来错误404当我从浏览器键入路由时找不到错误404
文件服务器示例代码:
r.Get(path, func(w http.ResponseWriter, r *http.Request) {
rctx := chi.RouteContext(r.Context()) // sets the route context
pathPrefix := strings.TrimSuffix(rctx.RoutePattern(), "/*") // this displays the path
fmt.Printf(pathPrefix + "\n")
fs := http.StripPrefix(pathPrefix, http.FileServer(root))
fs.ServeHTTP(w, r)
})
运行服务器时,它可以工作 当我单击水疗中心的路由器链接时,它可以正常工作 当我从浏览器中键入链接并且不使用水疗中心时,它不起作用并返回404
如何绕过它并为文件提供服务?
The Fileserver Example Code:
r.Get(path, func(w http.ResponseWriter, r *http.Request) {
rctx := chi.RouteContext(r.Context()) // sets the route context
pathPrefix := strings.TrimSuffix(rctx.RoutePattern(), "/*") // this displays the path
fmt.Printf(pathPrefix + "\n")
fs := http.StripPrefix(pathPrefix, http.FileServer(root))
fs.ServeHTTP(w, r)
})
When I run the server, it works
When I click on router-links from the SPA, it works
When I type a link in from the browser and not use the SPA, it doesnt work and returns 404
How do I bypass this and serve the files instead?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)