4f8750d4 by 张磊

1

1 parent a89f14d8
...@@ -18,6 +18,7 @@ import ( ...@@ -18,6 +18,7 @@ import (
18 "net/http" 18 "net/http"
19 "os" 19 "os"
20 "path" 20 "path"
21 "path/filepath"
21 "strconv" 22 "strconv"
22 "strings" 23 "strings"
23 24
...@@ -68,16 +69,25 @@ func serverStaticRouter(ctx *context.Context) { ...@@ -68,16 +69,25 @@ func serverStaticRouter(ctx *context.Context) {
68 if !DirectoryIndex { 69 if !DirectoryIndex {
69 exception("403", ctx) 70 exception("403", ctx)
70 return 71 return
71 } else if 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 }
75 } else if strings.HasSuffix(requestPath, "/index.html") { 76 } else if strings.HasSuffix(requestPath, "/index.html") {
76 file := path.Join(staticDir, requestPath) 77 //file := path.Join(staticDir, requestPath)
77 if utils.FileExists(file) { 78 //if utils.FileExists(file) {
78 http.ServeFile(ctx.ResponseWriter, ctx.Request, file) 79 //http.ServeFile(ctx.ResponseWriter, ctx.Request, file)
79 return 80 //return
80 } 81 //}
82
83 //http.ServeFile can not use index.html
84 dirName, fileName := filepath.Split(file)
85 fs := http.Dir(dirName)
86 f, _ := fs.Open(fileName)
87 defer f.Close()
88 d, _ := f.Stat()
89 http.ServeContent(ctx.ResponseWriter, ctx.Request, d.Name(), d.ModTime(), f)
90 return
81 } 91 }
82 92
83 //This block obtained from (https://github.com/smithfox/beego) - it should probably get merged into astaxie/beego after a pull request 93 //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!