We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
. ├─main.go └─webui └─index.html
package main import "github.com/xgfone/ship/v5" func main() { s := ship.Default() s.Route("/webui").Static("webui") // 只有注册的路由是 / 时 index.html 才正常访问 ship.StartServer(":8080", s) }
<h1>Hello Ship</h1>
访问 http://127.0.0.1:8080/webui 报 404
访问 http://127.0.0.1:8080/webui/index.html 依然报 404
注册静态文件路由时,调用 s.Route("/webui").Static("webui") ship 会注册两个路由:GET /webui/*path 和 HEAD /webui/*path
s.Route("/webui").Static("webui")
GET /webui/*path
HEAD /webui/*path
当浏览器访问 GET /webui/index.html 时 http.FileServer 会将 index.html 的结尾的Path重定向到 ./ ,即:将 GET /webui/index.html 重定向到 GET /webui/ ,而 /webui/ 无法命中 /webui/*path,导致 index.html 404
GET /webui/index.html
http.FileServer
./
GET /webui/
/webui/
/webui/*path
The text was updated successfully, but these errors were encountered:
我觉得 /path/* 是可以匹配到 /path 或 /path/,比如在正则中,* 就认为是可以匹配到零个或多个,在 gin 路由中,* 也是可以匹配零个或多个
/path/*
/path
/path/
Sorry, something went wrong.
这是因为:
Static
./webui
/index.html
ship.Default()
移除请求路径后缀 /
/webui
Path + "/*"
/webui/*
/
解决办法有两个:
s.Router = echo.NewRouter(&echo.Config{RemoveTrailingSlash: false})
s.Router = echo.NewRouter(nil)
v5.1.4
require github.com/xgfone/ship/v5 v5.1.4
No branches or pull requests
目录文件布局如下
main.go 内容如下:
webui/index.html 内容如下:
结果
访问 http://127.0.0.1:8080/webui 报 404
访问 http://127.0.0.1:8080/webui/index.html 依然报 404
原因分析
注册静态文件路由时,调用
s.Route("/webui").Static("webui")
ship 会注册两个路由:GET /webui/*path
和HEAD /webui/*path
当浏览器访问
GET /webui/index.html
时http.FileServer
会将 index.html 的结尾的Path重定向到./
,即:将GET /webui/index.html
重定向到GET /webui/
,而/webui/
无法命中/webui/*path
,导致 index.html 404The text was updated successfully, but these errors were encountered: