beego: improve static file index.html simple code
Showing
1 changed file
with
10 additions
and
2 deletions
| ... | @@ -65,13 +65,21 @@ func serverStaticRouter(ctx *context.Context) { | ... | @@ -65,13 +65,21 @@ 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 | if !DirectoryIndex { | ||
| 69 | middleware.Exception("403", ctx.ResponseWriter, ctx.Request, "403 Forbidden") | 70 | middleware.Exception("403", ctx.ResponseWriter, ctx.Request, "403 Forbidden") |
| 70 | return | 71 | return |
| 71 | } else if finfo.IsDir() && ctx.Input.Request.URL.Path[len(ctx.Input.Request.URL.Path)-1] != '/' { | 72 | } else if ctx.Input.Request.URL.Path[len(ctx.Input.Request.URL.Path)-1] != '/' { |
| 72 | http.Redirect(ctx.ResponseWriter, ctx.Request, ctx.Input.Request.URL.Path+"/", 302) | 73 | http.Redirect(ctx.ResponseWriter, ctx.Request, ctx.Input.Request.URL.Path+"/", 302) |
| 73 | return | 74 | return |
| 74 | } | 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 | } | ||
| 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 |
| 77 | isStaticFileToCompress := false | 85 | isStaticFileToCompress := false | ... | ... |
-
Please register or sign in to post a comment