diff --git a/routergroup.go b/routergroup.go index 5e681c1c..89f0d217 100644 --- a/routergroup.go +++ b/routergroup.go @@ -186,6 +186,18 @@ func (group *RouterGroup) createStaticHandler(relativePath string, fs http.FileS if nolisting { c.Writer.WriteHeader(404) } + + file := c.Param("filepath") + // Check existence of file + if _, err := fs.Open(file); err != nil { + c.handlers = group.engine.allNoRoute + // Since we change our handler to Router's NotFound, + // we need to reset the index + c.index = -1 + serveError(c, 404, default404Body) + return + } + fileServer.ServeHTTP(c.Writer, c.Request) } }