Skip to content

Commit

Permalink
recipes: static middleware changes
Browse files Browse the repository at this point in the history
Signed-off-by: Vishal Rana <[email protected]>
  • Loading branch information
vishr committed Oct 25, 2016
1 parent c978ff6 commit b127906
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 8 deletions.
10 changes: 8 additions & 2 deletions echo.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,9 +384,15 @@ func (e *Echo) Match(methods []string, path string, handler HandlerFunc, middlew
// Static registers a new route with path prefix to serve static files from the
// provided root directory.
func (e *Echo) Static(prefix, root string) {
e.GET(prefix+"*", func(c Context) error {
h := func(c Context) error {
return c.File(path.Join(root, c.Param("*")))
})
}
e.GET(prefix, h)
if prefix == "/" {
e.GET(prefix+"*", h)
} else {
e.GET(prefix+"/*", h)
}
}

// File registers a new route with path to serve a static file.
Expand Down
2 changes: 1 addition & 1 deletion recipe/file-upload/multiple/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ func main() {

e.Use(middleware.Logger())
e.Use(middleware.Recover())
e.Use(middleware.Static("public"))

e.Static("/", "public")
e.POST("/upload", upload)

if err := e.Start(":1323"); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion recipe/file-upload/single/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ func main() {

e.Use(middleware.Logger())
e.Use(middleware.Recover())
e.Use(middleware.Static("public"))

e.Static("/", "public")
e.POST("/upload", upload)

if err := e.Start(":1323"); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion recipe/google-app-engine/app-standalone.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func createMux() *echo.Echo {
e.Use(middleware.Logger())
e.Use(middleware.Gzip())

e.Use(middleware.Static("public"))
e.Static("/", "public")

return e
}
Expand Down
3 changes: 2 additions & 1 deletion recipe/jsonp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ func main() {
e := echo.New()
e.Use(middleware.Logger())
e.Use(middleware.Recover())
e.Use(middleware.Static("public"))

e.Static("/", "public")

// JSONP
e.GET("/jsonp", func(c echo.Context) error {
Expand Down
2 changes: 1 addition & 1 deletion recipe/websocket/gorilla/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func main() {
e := echo.New()
e.Use(middleware.Logger())
e.Use(middleware.Recover())
e.Use(middleware.Static("../public"))
e.Static("/", "../public")
e.GET("/ws", hello)
if err := e.Start(":1323"); err != nil {
e.Logger.Fatal(err)
Expand Down
2 changes: 1 addition & 1 deletion recipe/websocket/net/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func main() {
e := echo.New()
e.Use(middleware.Logger())
e.Use(middleware.Recover())
e.Use(middleware.Static("../public"))
e.Static("/", "../public")
e.GET("/ws", hello)
if err := e.Start(":1323"); err != nil {
e.Logger.Fatal(err)
Expand Down

0 comments on commit b127906

Please sign in to comment.