mirror of
https://github.com/labstack/echo.git
synced 2025-07-03 00:56:59 +02:00
Fixed default options for static
Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
@ -20,14 +20,17 @@ type (
|
|||||||
func Static(root string, options ...*StaticOptions) echo.MiddlewareFunc {
|
func Static(root string, options ...*StaticOptions) echo.MiddlewareFunc {
|
||||||
return func(next echo.Handler) echo.Handler {
|
return func(next echo.Handler) echo.Handler {
|
||||||
// Default options
|
// Default options
|
||||||
opts := &StaticOptions{Index: "index.html"}
|
opts := new(StaticOptions)
|
||||||
if len(options) > 0 {
|
if len(options) > 0 {
|
||||||
opts = options[0]
|
opts = options[0]
|
||||||
}
|
}
|
||||||
|
if opts.Index == "" {
|
||||||
|
opts.Index = "index.html"
|
||||||
|
}
|
||||||
|
|
||||||
return echo.HandlerFunc(func(c echo.Context) error {
|
return echo.HandlerFunc(func(c echo.Context) error {
|
||||||
fs := http.Dir(root)
|
fs := http.Dir(root)
|
||||||
file := c.Request().URI()
|
file := path.Clean(c.Request().URL().Path())
|
||||||
f, err := fs.Open(file)
|
f, err := fs.Open(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return next.Handle(c)
|
return next.Handle(c)
|
||||||
|
Reference in New Issue
Block a user