mirror of
https://github.com/labstack/echo.git
synced 2025-07-15 01:34:53 +02:00
Use the NotFoundHandler when a file haven't been found. (#966)
This is especialy usefull when you use e.Static("/", "static") and you want a notfoundhandler that serves your index.html like this: echo.NotFoundHandler = func(c2 echo.Context) error { index := filepath.Join(c.config.StaticDir, c.config.Index) _, err := os.Open(index) if err != nil { return echo.ErrNotFound } return c2.File(path.Join(c.config.StaticDir, c.config.Index)) } Another usecase with the Handler above is HTML5 SPF applications. One caveat, you need to make sure that your NotFoundHandler doesn't produce loops. Signed-off-by: Rene Jochum <rene@jochums.at>
This commit is contained in:
2
group.go
2
group.go
@ -21,7 +21,7 @@ func (g *Group) Use(middleware ...MiddlewareFunc) {
|
||||
// Allow all requests to reach the group as they might get dropped if router
|
||||
// doesn't find a match, making none of the group middleware process.
|
||||
g.echo.Any(path.Clean(g.prefix+"/*"), func(c Context) error {
|
||||
return ErrNotFound
|
||||
return NotFoundHandler(c)
|
||||
}, g.middleware...)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user