Update README.md

pull/198/head
Vic Shóstak 2020-03-01 18:24:46 +03:00 committed by GitHub
parent 9e3b3e4e89
commit 92cf5a34d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 30 additions and 0 deletions

30
.github/README.md vendored
View File

@ -263,6 +263,36 @@ func main() {
}
```
### Cross-Origin Resource Sharing (CORS)
[CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS) is a mechanism that uses additional HTTP headers to tell browsers to give a web application running at one origin, access to selected resources from a different origin. A web application executes a cross-origin HTTP request when it requests a resource that has a different origin (domain, protocol, or port) from its own.
```go
import (
"github.com/gofiber/fiber"
"github.com/gofiber/fiber/middleware" // all middleware are combined in a separate Go package
)
func main() {
app := fiber.New()
// Connect CORS for each route as middleware
app.Use(middleware.CORS())
app.Get("/", func(c *fiber.Ctx) {
c.Send("CORS is enabled!")
})
app.Listen(3000)
}
```
Check CORS by passing any domain in `Origin` header:
```bash
curl -H "Origin: http://example.com" --verbose http://localhost:3000`
```
### Custom 404 response
```go