From 95ef4c7136d3a02d183d22e964cbc41a74ee37cd Mon Sep 17 00:00:00 2001 From: astaxie Date: Mon, 21 Sep 2015 23:56:24 +0800 Subject: [PATCH] server index.html in beego with ServeContent --- staticfile.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/staticfile.go b/staticfile.go index 1ce9e561..fa8a56d4 100644 --- a/staticfile.go +++ b/staticfile.go @@ -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 } }