1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-22 07:30:55 +00:00

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

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
}
}