
go get -u github.com/gofiber/fiber
go get -u github.com/gofiber/cors
Property |
Type |
Description |
Default |
Filter |
func(*Ctx) bool |
Defines a function to skip middleware |
nil |
AllowOrigins |
[]string |
AllowOrigin defines a list of origins that may access the resource. |
[]string{"*"} |
AllowMethods |
[]string |
AllowMethods defines a list methods allowed when accessing the resource. This is used in response to a preflight request. |
[]string{"GET", "POST", "HEAD", "PUT", "DELETE", "PATCH"} |
AllowCredentials |
bool |
AllowCredentials indicates whether or not the response to the request can be exposed when the credentials flag is true. When used as part of a response to a preflight request, this indicates whether or not the actual request can be made using credentials. |
false |
ExposeHeaders |
[]string |
ExposeHeaders defines a whitelist headers that clients are allowed to access. |
[]string{} |
MaxAge |
int |
MaxAge indicates how long (in seconds) the results of a preflight request can be cached. |
0 |
package main
import (
"github.com/gofiber/fiber"
"github.com/gofiber/cors"
)
func main() {
app := fiber.New()
app.Use(cors.New())
app.Get("/", func(c *fiber.Ctx) {
c.Send("Welcome!")
})
app.Listen(3000)
}
curl -H "Origin: http://example.com" --verbose http://localhost:3000