From 3d8e6a03174c90a8eabafcd9941ae1ceb6578739 Mon Sep 17 00:00:00 2001 From: TangDandan Date: Wed, 13 Nov 2019 15:55:47 +0800 Subject: [PATCH] Modify core/router/api_builder.go When I use file-server like this ``` v1 := app.Party("/aa/bb") v1.HandleDir(/static, "./assets", iris.DirOptions{ IndexName: "/index.html", Gzip: false, ShowList: false, }) ``` and I request `http://localhost:8080/aa/bb/static` or `http://localhost:8080/aa/bb/cc/static/index.html`, it will be 404 NOT FOUND. Because the modified line will create a route `/aa/bb/aa/bb/static` which expected `/aa/bb/static` Thanks for your consideration. Former-commit-id: cb680a5f8c103e8c14986e1b64505f7faff6326d --- core/router/api_builder.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/router/api_builder.go b/core/router/api_builder.go index 0e80f36e..c90b36d1 100644 --- a/core/router/api_builder.go +++ b/core/router/api_builder.go @@ -485,7 +485,8 @@ func (api *APIBuilder) HandleDir(requestPath, directory string, opts ...DirOptio continue } - routes = append(routes, api.createRoutes([]string{http.MethodGet}, s.RequestPath, h)...) + requestPath := s.RequestPath[strings.Index(s.RequestPath, api.relativePath)+len(api.relativePath):] + routes = append(routes, api.createRoutes([]string{http.MethodGet}, requestPath, h)...) getRoute.StaticSites = append(getRoute.StaticSites, s) }