mirror of
https://github.com/labstack/echo.git
synced 2025-01-12 01:22:21 +02:00
fixed recipes for static middleware change
Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
parent
166a24fe23
commit
4760f4cedf
6
group.go
6
group.go
@ -19,7 +19,11 @@ func (g *Group) Use(middleware ...MiddlewareFunc) {
|
|||||||
// Allow requests `/prefix & /prefix/*` to reach the group as they might get
|
// Allow requests `/prefix & /prefix/*` to reach the group as they might get
|
||||||
// dropped if router doesn't find a match, making none of the group middleware
|
// dropped if router doesn't find a match, making none of the group middleware
|
||||||
// execute.
|
// execute.
|
||||||
g.Any("", NotFoundHandler, g.middleware...)
|
p := ""
|
||||||
|
if g.prefix == "" {
|
||||||
|
p = "/"
|
||||||
|
}
|
||||||
|
g.Any(p, NotFoundHandler, g.middleware...)
|
||||||
g.Any("/*", NotFoundHandler, g.middleware...)
|
g.Any("/*", NotFoundHandler, g.middleware...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ type (
|
|||||||
Skipper Skipper
|
Skipper Skipper
|
||||||
|
|
||||||
// Prefix to strip from the request URL path.
|
// Prefix to strip from the request URL path.
|
||||||
// Required.
|
// Optional. Default value "".
|
||||||
Prefix string `json:"root"`
|
Prefix string `json:"root"`
|
||||||
|
|
||||||
// Root directory from where the static content is served.
|
// Root directory from where the static content is served.
|
||||||
@ -48,9 +48,8 @@ var (
|
|||||||
|
|
||||||
// Static returns a Static middleware to serves static content from the provided
|
// Static returns a Static middleware to serves static content from the provided
|
||||||
// root directory.
|
// root directory.
|
||||||
func Static(prefix, root string) echo.MiddlewareFunc {
|
func Static(root string) echo.MiddlewareFunc {
|
||||||
c := DefaultStaticConfig
|
c := DefaultStaticConfig
|
||||||
c.Prefix = prefix
|
|
||||||
c.Root = root
|
c.Root = root
|
||||||
return StaticWithConfig(c)
|
return StaticWithConfig(c)
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,7 @@ func main() {
|
|||||||
|
|
||||||
e.Use(middleware.Logger())
|
e.Use(middleware.Logger())
|
||||||
e.Use(middleware.Recover())
|
e.Use(middleware.Recover())
|
||||||
e.Use(middleware.Static("public"))
|
e.Use(middleware.Static( "public"))
|
||||||
|
|
||||||
e.POST("/upload", upload)
|
e.POST("/upload", upload)
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ func main() {
|
|||||||
|
|
||||||
e.Use(middleware.Logger())
|
e.Use(middleware.Logger())
|
||||||
e.Use(middleware.Recover())
|
e.Use(middleware.Recover())
|
||||||
e.Use(middleware.Static("public"))
|
e.Use(middleware.Static( "public"))
|
||||||
|
|
||||||
e.POST("/upload", upload)
|
e.POST("/upload", upload)
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ func createMux() *echo.Echo {
|
|||||||
e.Use(middleware.Logger())
|
e.Use(middleware.Logger())
|
||||||
e.Use(middleware.Gzip())
|
e.Use(middleware.Gzip())
|
||||||
|
|
||||||
e.Use(middleware.Static("public"))
|
e.Use(middleware.Static( "public"))
|
||||||
|
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ func main() {
|
|||||||
e := echo.New()
|
e := echo.New()
|
||||||
e.Use(middleware.Logger())
|
e.Use(middleware.Logger())
|
||||||
e.Use(middleware.Recover())
|
e.Use(middleware.Recover())
|
||||||
e.Use(middleware.Static("public"))
|
e.Use(middleware.Static( "public"))
|
||||||
|
|
||||||
// JSONP
|
// JSONP
|
||||||
e.GET("/jsonp", func(c echo.Context) error {
|
e.GET("/jsonp", func(c echo.Context) error {
|
||||||
|
@ -41,7 +41,7 @@ func main() {
|
|||||||
e := echo.New()
|
e := echo.New()
|
||||||
e.Use(middleware.Logger())
|
e.Use(middleware.Logger())
|
||||||
e.Use(middleware.Recover())
|
e.Use(middleware.Recover())
|
||||||
e.Use(middleware.Static("../public"))
|
e.Use(middleware.Static( "../public"))
|
||||||
e.GET("/ws", hello)
|
e.GET("/ws", hello)
|
||||||
if err := e.Start(":1323"); err != nil {
|
if err := e.Start(":1323"); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
@ -35,7 +35,7 @@ func main() {
|
|||||||
e := echo.New()
|
e := echo.New()
|
||||||
e.Use(middleware.Logger())
|
e.Use(middleware.Logger())
|
||||||
e.Use(middleware.Recover())
|
e.Use(middleware.Recover())
|
||||||
e.Use(middleware.Static("../public"))
|
e.Use(middleware.Static( "../public"))
|
||||||
e.GET("/ws", hello)
|
e.GET("/ws", hello)
|
||||||
if err := e.Start(":1323"); err != nil {
|
if err := e.Start(":1323"); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
Loading…
Reference in New Issue
Block a user