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:
parent
c978ff6431
commit
b12790607e
10
echo.go
10
echo.go
@ -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.
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user