server index.html in beego with ServeContent

This commit is contained in:
astaxie 2015-09-21 23:56:24 +08:00
parent eb85e8e328
commit 95ef4c7136
1 changed files with 9 additions and 1 deletions

View File

@ -74,7 +74,15 @@ func serverStaticRouter(ctx *context.Context) {
} else if strings.HasSuffix(requestPath, "/index.html") {
file := path.Join(staticDir, requestPath)
if utils.FileExists(file) {
http.ServeFile(ctx.ResponseWriter, ctx.Request, file)
oFile, err := os.Open(file)
if err != nil {
if RunMode == "dev" {
Warn("Can't open the file:", file, err)
}
http.NotFound(ctx.ResponseWriter, ctx.Request)
}
defer oFile.Close()
http.ServeContent(ctx.ResponseWriter, ctx.Request, file, finfo.ModTime(), oFile)
return
}
}