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
This commit is contained in:
TangDandan 2019-11-13 15:55:47 +08:00
parent 7ad97865b5
commit 3d8e6a0317

View File

@ -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)
}