Skip to content

Commit

Permalink
fix(middleware/cors): Update Next function signature
Browse files Browse the repository at this point in the history
  • Loading branch information
sixcolors committed Mar 18, 2024
1 parent e1b808e commit 7475036
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/api/middleware/cors.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ panic: [CORS] 'AllowCredentials' is true, but 'AllowOrigins' cannot be set to `"

| Property | Type | Description | Default |
|:-----------------|:---------------------------|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:-----------------------------------|
| Next | `func(*fiber.Ctx) bool` | Next defines a function to skip this middleware when returned true. | `nil` |
| Next | `func(fiber.Ctx) bool` | Next defines a function to skip this middleware when returned true. | `nil` |
| AllowOriginsFunc | `func(origin string) bool` | `AllowOriginsFunc` is a function that dynamically determines whether to allow a request based on its origin. If this function returns `true`, the 'Access-Control-Allow-Origin' response header will be set to the request's 'origin' header. This function is only used if the request's origin doesn't match any origin in `AllowOrigins`. | `nil` |
| AllowOrigins | `string` | AllowOrigins defines a comma separated list of origins that may access the resource. This supports subdomain matching, so you can use a value like "https://*.example.com" to allow any subdomain of example.com to submit requests. | `"*"` |
| AllowMethods | `string` | AllowMethods defines a list of methods allowed when accessing the resource. This is used in response to a preflight request. | `"GET,POST,HEAD,PUT,DELETE,PATCH"` |
Expand Down
4 changes: 2 additions & 2 deletions middleware/cors/cors.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type Config struct {
// Next defines a function to skip this middleware when returned true.
//
// Optional. Default: nil
Next func(c *fiber.Ctx) bool
Next func(c fiber.Ctx) bool

// AllowOriginsFunc defines a function that will set the 'Access-Control-Allow-Origin'
// response header to the 'origin' request header when returned true. This allows for
Expand Down Expand Up @@ -165,7 +165,7 @@ func New(config ...Config) fiber.Handler {
// Return new handler
return func(c fiber.Ctx) error {
// Don't execute middleware if Next returns true
if cfg.Next != nil && cfg.Next(&c) {
if cfg.Next != nil && cfg.Next(c) {
return c.Next()
}

Expand Down
2 changes: 1 addition & 1 deletion middleware/cors/cors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ func Test_CORS_Next(t *testing.T) {
t.Parallel()
app := fiber.New()
app.Use(New(Config{
Next: func(_ *fiber.Ctx) bool {
Next: func(_ fiber.Ctx) bool {
return true
},
}))
Expand Down

0 comments on commit 7475036

Please sign in to comment.