diff --git a/group.go b/group.go index 72c0c71c..2b6898b2 100644 --- a/group.go +++ b/group.go @@ -14,13 +14,13 @@ type ( ) // Use implements `Echo#Use()` for sub-routes within the Group. -func (g *Group) Use(m ...MiddlewareFunc) { - g.middleware = append(g.middleware, m...) +func (g *Group) Use(middleware ...MiddlewareFunc) { + g.middleware = append(g.middleware, middleware...) // Allow requests `/prefix & /prefix/*` to reach the group as they might get // dropped if router doesn't find a match, making none of the group middleware // execute. - g.echo.Any(g.prefix, NotFoundHandler, g.middleware...) - g.echo.Any(g.prefix+"/*", NotFoundHandler, g.middleware...) + g.Any("", NotFoundHandler, g.middleware...) + g.Any("/*", NotFoundHandler, g.middleware...) } // CONNECT implements `Echo#CONNECT()` for sub-routes within the Group. @@ -93,7 +93,7 @@ func (g *Group) Group(prefix string, middleware ...MiddlewareFunc) *Group { // Static implements `Echo#Static()` for sub-routes within the Group. func (g *Group) Static(prefix, root string) { g.GET(g.prefix+prefix+"*", func(c Context) error { - return c.File(path.Join(root, c.Param("_*"))) + return c.File(path.Join(root, c.Param("*"))) }) } diff --git a/middleware/redirect.go b/middleware/redirect.go index 94c2e19a..8e926c75 100644 --- a/middleware/redirect.go +++ b/middleware/redirect.go @@ -58,7 +58,6 @@ func HTTPSRedirectWithConfig(config RedirectConfig) echo.MiddlewareFunc { req := c.Request() host := req.Host uri := req.RequestURI - println(uri) if !c.IsTLS() { return c.Redirect(config.Code, "https://"+host+uri) } diff --git a/middleware/static.go b/middleware/static.go index 55af74a2..202e557a 100644 --- a/middleware/static.go +++ b/middleware/static.go @@ -15,6 +15,10 @@ type ( // Skipper defines a function to skip middleware. Skipper Skipper + // Prefix to strip from the request URL path. + // Required. + Prefix string `json:"root"` + // Root directory from where the static content is served. // Required. Root string `json:"root"` @@ -44,8 +48,9 @@ var ( // Static returns a Static middleware to serves static content from the provided // root directory. -func Static(root string) echo.MiddlewareFunc { +func Static(prefix, root string) echo.MiddlewareFunc { c := DefaultStaticConfig + c.Prefix = prefix c.Root = root return StaticWithConfig(c) } @@ -68,10 +73,8 @@ func StaticWithConfig(config StaticConfig) echo.MiddlewareFunc { } fs := http.Dir(config.Root) - p := c.Request().URL.Path - if strings.Contains(c.Path(), "*") { // If serving from a group, e.g. `/static*`. - p = c.Param("*") - } + p := strings.TrimPrefix(c.Request().URL.Path, config.Prefix) + println(p) file := path.Clean(p) f, err := fs.Open(file) if err != nil { diff --git a/router_test.go b/router_test.go index 89fca3cf..e5e68d27 100644 --- a/router_test.go +++ b/router_test.go @@ -347,7 +347,7 @@ func TestRouterMatchAny(t *testing.T) { c := e.NewContext(nil, nil).(*context) r.Find(GET, "/", c) - assert.Equal(t, "", c.Param("_*")) + assert.Equal(t, "", c.Param("*")) r.Find(GET, "/download", c) assert.Equal(t, "download", c.Param("*"))