1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-18 18:37:05 +00:00

Update to version 10.2.1 - fix StaticEmbedded & StaticWeb when served from a subdomain. Read https://github.com/kataras/iris/blob/master/HISTORY.md#th-15-february-2018--v1021

Former-commit-id: 9bc3ed63fadbb4fb38abef06115b5d6d760256f0
This commit is contained in:
Gerasimos (Makis) Maropoulos
2018-02-15 13:01:13 +02:00
parent ffc3ec86ae
commit d4993e6a3f
10 changed files with 38 additions and 12 deletions

View File

@@ -617,6 +617,12 @@ func (api *APIBuilder) StaticEmbeddedHandler(vdir string, assetFn func(name stri
// Examples: https://github.com/kataras/iris/tree/master/_examples/file-server
func (api *APIBuilder) StaticEmbedded(requestPath string, vdir string, assetFn func(name string) ([]byte, error), namesFn func() []string) *Route {
fullpath := joinPath(api.relativePath, requestPath)
// if subdomain,
// here we get the full path of the path only,
// because a subdomain can have parties as well
// and we need that path to call the `StripPrefix`.
_, fullpath = splitSubdomainAndPath(fullpath)
requestPath = joinPath(fullpath, WildcardParam("file"))
h := api.StaticEmbeddedHandler(vdir, assetFn, namesFn)
@@ -625,6 +631,7 @@ func (api *APIBuilder) StaticEmbedded(requestPath string, vdir string, assetFn f
h = StripPrefix(fullpath, h)
}
// it handles the subdomain(root Party) of this party as well, if any.
return api.registerResourceRoute(requestPath, h)
}
@@ -705,19 +712,24 @@ func (api *APIBuilder) Favicon(favPath string, requestPath ...string) *Route {
//
// Returns the GET *Route.
func (api *APIBuilder) StaticWeb(requestPath string, systemPath string) *Route {
paramName := "file"
fullpath := joinPath(api.relativePath, requestPath)
// if subdomain,
// here we get the full path of the path only,
// because a subdomain can have parties as well
// and we need that path to call the `StripPrefix`.
_, fullpath = splitSubdomainAndPath(fullpath)
h := StripPrefix(fullpath, NewStaticHandlerBuilder(systemPath).Listing(false).Build())
requestPath = joinPath(fullpath, WildcardParam(paramName))
h := NewStaticHandlerBuilder(systemPath).Listing(false).Build()
handler := func(ctx context.Context) {
h(ctx)
if fullpath != "/" {
h = StripPrefix(fullpath, h)
}
requestPath = joinPath(requestPath, WildcardParam(paramName))
return api.registerResourceRoute(requestPath, handler)
// it handles the subdomain(root Party) of this party as well, if any.
return api.registerResourceRoute(requestPath, h)
}
// OnErrorCode registers an error http status code