1
0
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:
Vishal Rana 2017-02-23 12:27:48 -08:00
parent 29fd5831ff
commit 049518f8c4
2 changed files with 13 additions and 1 deletions

View File

@ -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
// provided root directory.
func (e *Echo) Static(prefix, root string) {
if root == "" {
root = "." // For security we want to restrict to CWD.
}
static(e, prefix, root)
}

View File

@ -88,8 +88,17 @@ func StaticWithConfig(config StaticConfig) echo.MiddlewareFunc {
if config.Browse {
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)
}
}