mirror of
https://github.com/kataras/iris.git
synced 2025-02-02 15:30:36 +01:00
This commit is contained in:
parent
374bfa890c
commit
a4fbf4db4e
16
iris.go
16
iris.go
|
@ -1665,22 +1665,20 @@ func StaticWeb(reqPath string, systemPath string, stripSlashes int) RouteNameFun
|
||||||
// * stripSlashes = 1, original path: "/foo/bar", result: "/bar"
|
// * stripSlashes = 1, original path: "/foo/bar", result: "/bar"
|
||||||
// * stripSlashes = 2, original path: "/foo/bar", result: ""
|
// * stripSlashes = 2, original path: "/foo/bar", result: ""
|
||||||
// * if you don't know what to put on stripSlashes just 1
|
// * 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 {
|
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
|
if reqPath[len(reqPath)-1] != slashByte { // if / then /*filepath, if /something then /something/*filepath
|
||||||
reqPath += slash
|
reqPath += slash
|
||||||
}
|
}
|
||||||
|
|
||||||
hasIndex := utils.Exists(systemPath + utils.PathSeparator + "index.html")
|
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
|
var indexNames []string
|
||||||
indexHandler := func(ctx *Context) {
|
if hasIndex {
|
||||||
if len(ctx.Param("filepath")) < 2 && hasIndex {
|
indexNames = []string{"index.html"}
|
||||||
ctx.Request.SetRequestURI("index.html")
|
|
||||||
}
|
}
|
||||||
ctx.Next()
|
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)
|
||||||
api.Head(reqPath+"*filepath", indexHandler, serveHandler)
|
|
||||||
return api.Get(reqPath+"*filepath", indexHandler, serveHandler)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// StaticServe serves a directory as web resource
|
// StaticServe serves a directory as web resource
|
||||||
|
|
Loading…
Reference in New Issue
Block a user