1
0
mirror of https://github.com/gofiber/fiber.git synced 2025-02-12 02:41:05 +00:00

add Next function to app.Static config

This commit is contained in:
Martin Lukasik 2021-01-22 23:07:22 +01:00
parent ba7fc034c2
commit 3a132d0b98
2 changed files with 9 additions and 0 deletions

5
app.go
View File

@ -302,6 +302,11 @@ type Static struct {
//
// Optional. Default value 0.
MaxAge int `json:"max_age"`
// Next defines a function to skip this middleware when returned true.
//
// Optional. Default: nil
Next func(c *Ctx) bool
}
// Default Config values

View File

@ -359,6 +359,10 @@ func (app *App) registerStatic(prefix, root string, config ...Static) Router {
}
fileHandler := fs.NewRequestHandler()
handler := func(c *Ctx) error {
// Don't execute middleware if Next returns true
if config[0].Next != nil && config[0].Next(c) {
return c.Next()
}
// Serve file
fileHandler(c.fasthttp)
// Return request if found and not forbidden