31e61334 by astaxie

beego: improve static file index.html simple code

1 parent 3a5de83e
...@@ -65,12 +65,20 @@ func serverStaticRouter(ctx *context.Context) { ...@@ -65,12 +65,20 @@ func serverStaticRouter(ctx *context.Context) {
65 return 65 return
66 } 66 }
67 //if the request is dir and DirectoryIndex is false then 67 //if the request is dir and DirectoryIndex is false then
68 if finfo.IsDir() && !DirectoryIndex { 68 if finfo.IsDir() {
69 middleware.Exception("403", ctx.ResponseWriter, ctx.Request, "403 Forbidden") 69 if !DirectoryIndex {
70 return 70 middleware.Exception("403", ctx.ResponseWriter, ctx.Request, "403 Forbidden")
71 } else if finfo.IsDir() && ctx.Input.Request.URL.Path[len(ctx.Input.Request.URL.Path)-1] != '/' { 71 return
72 http.Redirect(ctx.ResponseWriter, ctx.Request, ctx.Input.Request.URL.Path+"/", 302) 72 } else if ctx.Input.Request.URL.Path[len(ctx.Input.Request.URL.Path)-1] != '/' {
73 return 73 http.Redirect(ctx.ResponseWriter, ctx.Request, ctx.Input.Request.URL.Path+"/", 302)
74 return
75 }
76 } else if strings.HasSuffix(requestPath, "/index.html") {
77 file := path.Join(staticDir, requestPath)
78 if utils.FileExists(file) {
79 http.ServeFile(ctx.ResponseWriter, ctx.Request, file)
80 return
81 }
74 } 82 }
75 83
76 //This block obtained from (https://github.com/smithfox/beego) - it should probably get merged into astaxie/beego after a pull request 84 //This block obtained from (https://github.com/smithfox/beego) - it should probably get merged into astaxie/beego after a pull request
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!