From a4fbf4db4e133cf30244e6a85ca789fb330947ba Mon Sep 17 00:00:00 2001 From: Gerasimos Maropoulos Date: Tue, 9 Aug 2016 22:12:03 +0300 Subject: [PATCH] Fix https://github.com/kataras/iris/issues/350 --- README.md | 2 +- iris.go | 16 +++++++--------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 262dd9e3..1e65aa58 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ If you'd like to discuss this package, or ask questions about it, feel free to New website-docs & logo have been designed by the community[*](https://github.com/kataras/iris/issues/153) -- Website created by [@kujtimiihoxha](https://github.com/kujtimiihoxha) +- Website created by [@kujtimiihoxha](https://github.com/kujtimiihoxha) - Logo designed by [@OneebMalik](https://github.com/OneebMalik) diff --git a/iris.go b/iris.go index ab0b8fa5..ebf0e629 100644 --- a/iris.go +++ b/iris.go @@ -1665,22 +1665,20 @@ func StaticWeb(reqPath string, systemPath string, stripSlashes int) RouteNameFun // * stripSlashes = 1, original path: "/foo/bar", result: "/bar" // * stripSlashes = 2, original path: "/foo/bar", result: "" // * if you don't know what to put on stripSlashes just 1 +// example: https://github.com/iris-contrib/examples/tree/master/static_web func (api *muxAPI) StaticWeb(reqPath string, systemPath string, stripSlashes int) RouteNameFunc { if reqPath[len(reqPath)-1] != slashByte { // if / then /*filepath, if /something then /something/*filepath reqPath += slash } hasIndex := utils.Exists(systemPath + utils.PathSeparator + "index.html") - serveHandler := api.StaticHandler(systemPath, stripSlashes, false, !hasIndex, nil) // if not index.html exists then generate index.html which shows the list of files - indexHandler := func(ctx *Context) { - if len(ctx.Param("filepath")) < 2 && hasIndex { - ctx.Request.SetRequestURI("index.html") - } - ctx.Next() - + var indexNames []string + if hasIndex { + indexNames = []string{"index.html"} } - api.Head(reqPath+"*filepath", indexHandler, serveHandler) - return api.Get(reqPath+"*filepath", indexHandler, serveHandler) + serveHandler := api.StaticHandler(systemPath, stripSlashes, false, !hasIndex, indexNames) // if not index.html exists then generate index.html which shows the list of files + api.Head(reqPath+"*filepath", serveHandler) + return api.Get(reqPath+"*filepath", serveHandler) } // StaticServe serves a directory as web resource