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:
parent
ba7fc034c2
commit
3a132d0b98
5
app.go
5
app.go
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user