mirror of
https://github.com/kataras/iris.git
synced 2025-03-13 21:36:28 +01:00
(silly) Fix https://github.com/kataras/iris/issues/633
Former-commit-id: 0359fbf7dd3ff151db7b0575510e611bed683d0e
This commit is contained in:
parent
42cf24fda2
commit
4de98254fd
|
@ -34,6 +34,7 @@ Fixes:
|
|||
- Fix and improve the cloud-editor `alm/alm-tools` plugin(now adaptor)
|
||||
- Fix gorillamux serve static files (custom routers are supported with a workaround, not a complete solution as they are now)
|
||||
- Fix `iris run main.go` app reload while user saved the file from gogland
|
||||
- Fix [StaticEmbedded doesn't works on root "/"](https://github.com/kataras/iris/issues/633)
|
||||
|
||||
Changes:
|
||||
|
||||
|
|
|
@ -62,8 +62,16 @@ func New() iris.Policies {
|
|||
RouterReversionPolicy: iris.RouterReversionPolicy{
|
||||
// path normalization done on iris' side
|
||||
StaticPath: staticPath,
|
||||
WildcardPath: func(requestPath string, paramName string) string {
|
||||
return requestPath + "/{" + paramName + ":.*}"
|
||||
WildcardPath: func(path string, paramName string) string {
|
||||
// {param:.*}
|
||||
wildcardPart := "{" + paramName + ":.*}"
|
||||
|
||||
if path[len(path)-1] != '/' {
|
||||
// if not ending with slash then prepend the slash to the wildcard path part
|
||||
wildcardPart = "/" + wildcardPart
|
||||
}
|
||||
// finally return the path given + the wildcard path part
|
||||
return path + wildcardPart
|
||||
},
|
||||
// Note: on gorilla mux the {{ url }} and {{ path}} should give the key and the value, not only the values by order.
|
||||
// {{ url "nameOfTheRoute" "parameterName" "parameterValue"}}.
|
||||
|
|
|
@ -536,7 +536,15 @@ func New() iris.Policies {
|
|||
return path
|
||||
},
|
||||
WildcardPath: func(path string, paramName string) string {
|
||||
return path + slash + matchEverythingString + paramName
|
||||
// *param
|
||||
wildcardPart := matchEverythingString + paramName
|
||||
|
||||
if path[len(path)-1] != slashByte {
|
||||
// if not ending with slash then prepend the slash to the wildcard path part
|
||||
wildcardPart = slash + wildcardPart
|
||||
}
|
||||
// finally return the path given + the wildcard path part
|
||||
return path + wildcardPart
|
||||
},
|
||||
// path = "/api/users/:id", args = ["42"]
|
||||
// return "/api/users/42"
|
||||
|
|
|
@ -285,11 +285,19 @@ type (
|
|||
)
|
||||
|
||||
func normalizePath(path string) string {
|
||||
// some users can't understand the difference between
|
||||
// request path and operating system's directory path
|
||||
// they think that "./" is the index, that's wrong, "/" is the index
|
||||
// so fix that here...
|
||||
if path[0] == '.' {
|
||||
path = path[1:]
|
||||
}
|
||||
path = strings.Replace(path, "//", "/", -1)
|
||||
if len(path) > 1 && strings.IndexByte(path, '/') == len(path)-1 {
|
||||
// if it's not "/" and ending with slash remove that slash
|
||||
path = path[0 : len(path)-2]
|
||||
}
|
||||
|
||||
return path
|
||||
}
|
||||
|
||||
|
|
11
router.go
11
router.go
|
@ -487,7 +487,9 @@ func (router *Router) StaticContent(reqPath string, cType string, content []byte
|
|||
// example: https://github.com/iris-contrib/examples/tree/master/static_files_embedded
|
||||
func (router *Router) StaticEmbedded(requestPath string, vdir string, assetFn func(name string) ([]byte, error), namesFn func() []string) RouteInfo {
|
||||
paramName := "path"
|
||||
requestPath = router.Context.Framework().policies.RouterReversionPolicy.WildcardPath(requestPath, paramName)
|
||||
s := router.Context.Framework()
|
||||
|
||||
requestPath = s.policies.RouterReversionPolicy.WildcardPath(requestPath, paramName)
|
||||
|
||||
if len(vdir) > 0 {
|
||||
if vdir[0] == '.' { // first check for .wrong
|
||||
|
@ -512,20 +514,17 @@ func (router *Router) StaticEmbedded(requestPath string, vdir string, assetFn fu
|
|||
path = strings.Replace(path, "./", "/", -1) // replace ./assets/favicon.ico to /assets/favicon.ico in order to be ready for compare with the reqPath later
|
||||
path = path[len(vdir):] // set it as the its 'relative' ( we should re-setted it when assetFn will be used)
|
||||
names = append(names, path)
|
||||
|
||||
}
|
||||
|
||||
if len(names) == 0 {
|
||||
// we don't start the server yet, so:
|
||||
panic("iris.StaticEmbedded: Unable to locate any embedded files located to the (virtual) directory: " + vdir)
|
||||
s.Log(ProdMode, "error on StaticEmbedded: unable to locate any embedded files located to the (virtual) directory: "+vdir)
|
||||
}
|
||||
|
||||
modtime := time.Now()
|
||||
h := func(ctx *Context) {
|
||||
|
||||
reqPath := ctx.Param(paramName)
|
||||
|
||||
for _, path := range names {
|
||||
|
||||
if path != reqPath {
|
||||
continue
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user