mirror of
https://github.com/labstack/echo.git
synced 2024-12-24 20:14:31 +02:00
Fixed static middleware
Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
parent
29fd5831ff
commit
049518f8c4
3
echo.go
3
echo.go
@ -399,6 +399,9 @@ func (e *Echo) Match(methods []string, path string, handler HandlerFunc, middlew
|
|||||||
// Static registers a new route with path prefix to serve static files from the
|
// Static registers a new route with path prefix to serve static files from the
|
||||||
// provided root directory.
|
// provided root directory.
|
||||||
func (e *Echo) Static(prefix, root string) {
|
func (e *Echo) Static(prefix, root string) {
|
||||||
|
if root == "" {
|
||||||
|
root = "." // For security we want to restrict to CWD.
|
||||||
|
}
|
||||||
static(e, prefix, root)
|
static(e, prefix, root)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,8 +88,17 @@ func StaticWithConfig(config StaticConfig) echo.MiddlewareFunc {
|
|||||||
if config.Browse {
|
if config.Browse {
|
||||||
return listDir(name, c.Response())
|
return listDir(name, c.Response())
|
||||||
}
|
}
|
||||||
return c.File(filepath.Join(name, config.Index))
|
name = filepath.Join(name, config.Index)
|
||||||
|
fi, err = os.Stat(name)
|
||||||
|
if err != nil {
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
return next(c)
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return c.File(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.File(name)
|
return c.File(name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user