diff --git a/echo.go b/echo.go index 5a74c0bb..6a16b514 100644 --- a/echo.go +++ b/echo.go @@ -293,7 +293,7 @@ func (e *Echo) add(method, path string, h Handler) { // Static serves static files. func (e *Echo) Static(path, root string) { fs := http.StripPrefix(path, http.FileServer(http.Dir(root))) - e.Get(path+"/*", func(c *Context) *HTTPError { + e.Get(path+"*", func(c *Context) *HTTPError { fs.ServeHTTP(c.Response, c.Request) return nil }) diff --git a/examples/web/server.go b/examples/web/server.go index a1aaf570..ba321230 100644 --- a/examples/web/server.go +++ b/examples/web/server.go @@ -89,7 +89,7 @@ func main() { e.Favicon("public/favicon.ico") // Serve static files - e.Static("/scripts", "public/scripts") + e.Static("/scripts/", "public/scripts") //-------- // Routes diff --git a/website/docs/guide.md b/website/docs/guide.md index 930c2dfa..9f49fcc7 100644 --- a/website/docs/guide.md +++ b/website/docs/guide.md @@ -193,18 +193,17 @@ Sends an HTML HTTP response with status code. ### Static files -`echo.Static(path, root string)` serves static files. For example, code below -serves all files from `public/scripts` directory for any path starting -with `/scripts/` +`echo.Static(path, root string)` serves static files. For example, code below serves +files from directory `public/scripts` for any URL path starting with `/scripts/`. ```go -e.Static("/scripts", "public/scripts") +e.Static("/scripts/", "public/scripts") ``` ### Serving a file `echo.ServeFile(path, file string)` serves a file. For example, code below serves -welcome.html for path `/welcome` +file `welcome.html` for URL path `/welcome`. ```go e.ServeFile("/welcome", "welcome.html") @@ -212,13 +211,22 @@ e.ServeFile("/welcome", "welcome.html") ### Serving an index file -`echo.Index(file string)` serves an index file. For example, code below serves -index.html for path `/` +`echo.Index(file string)` serves an index file. For example, code below serves file +`index.html`. ```go e.Index("index.html") ``` +### Serving favicon + +`echo.Favicon(file string)` serves default favicon - `GET /favicon.ico`. For example, +code below serves file `favicon.ico`. + +```go +e.Index("public/favicon.ico") +``` + ## Error Handling Echo advocates centralized HTTP error handling by returning `*echo.HTTPError` from