New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
✨ add Next function to app.Static config #1130
Conversation
Thanks for opening this pull request! 🎉 Please check out our contributing guidelines. If you need help or want to chat with us, join us on Discord https://gofiber.io/discord |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please add some test cases?
Sure, and thanks for reply!) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mlukasik-dev
Could you add the new options also in the gofiber docs repository
https://github.com/gofiber/docs/blob/master/api/app.md
@ReneWerner87 |
// Next defines a function to skip this middleware when returned true. | ||
// | ||
// Optional. Default: nil | ||
Next func(c *Ctx) bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you change this to the Handler
type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assuming that you're talking about this Handler
type:
// Handler defines a function to serve HTTP requests.
type Handler = func(*Ctx) error
I'm not sure under what circumstances the middleware should be skipped.
If Handler
returns nil
or error
?
Here is current login of app.Static
:
// Don't execute middleware if Next returns true
if config != nil && config[0].Next != nil && config[0].Next(c) {
return c.Next()
}
// Serve file
// ...
@Fenny |
@mlukasik-dev totally missed the |
Congrats on merging your first pull request! 🎉 We here at Fiber are proud of you! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord |
Please provide enough information so that others can review your pull request:
I've added option to to skip app.Static middleware. Mechanism is identical with proxy.Config.Next function from
proxy
middleware.Explain the details for making this change. What existing problem does the pull request solve?
This can be feature is crucial for example when you want to serve different static files based on whether the user is authenticated.
Or when you just want to protect static file from unauthenticated users.
Commit formatting
Use emojis on commit messages so it provides an easy way of identifying the purpose or intention of a commit. Check out the emoji cheatsheet here: https://gitmoji.carloscuesta.me/