From 6c92ca2a16088eb99de7fcd84126a47f9d2623b4 Mon Sep 17 00:00:00 2001 From: "asta.xie" Date: Wed, 12 Mar 2014 17:03:34 +0800 Subject: [PATCH] fix bug for static file like /static /static_js /static_css --- router.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/router.go b/router.go index 6a7f8bf6..a4e8bf08 100644 --- a/router.go +++ b/router.go @@ -548,11 +548,16 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request) for prefix, staticDir := range StaticDir { if r.URL.Path == "/favicon.ico" { file := path.Join(staticDir, r.URL.Path) - http.ServeFile(w, r, file) - w.started = true - goto Admin + if utils.FileExists(file) { + http.ServeFile(w, r, file) + w.started = true + goto Admin + } } if strings.HasPrefix(r.URL.Path, prefix) { + if len(r.URL.Path) > len(prefix) && r.URL.Path[len(prefix)+1] != '/' { + continue + } file := path.Join(staticDir, r.URL.Path[len(prefix):]) finfo, err := os.Stat(file) if err != nil {