1
0
mirror of https://github.com/labstack/echo.git synced 2024-11-28 08:38:39 +02:00

recipes: static middleware changes

Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
Vishal Rana 2016-10-25 16:30:44 -07:00
parent c978ff6431
commit b12790607e
7 changed files with 15 additions and 8 deletions

10
echo.go
View File

@ -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.

View File

@ -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 {

View File

@ -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 {

View File

@ -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
}

View File

@ -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 {

View File

@ -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)

View File

@ -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)