Skip to content

Commit

Permalink
Fix README
Browse files Browse the repository at this point in the history
Update a few awkward turns of phrase and fix indentation in the example.
  • Loading branch information
akshayjshah committed Nov 21, 2023
1 parent 2255f80 commit 9c2a800
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,35 @@ cors
[![Report Card](https://goreportcard.com/badge/connectrpc.com/cors)](https://goreportcard.com/report/connectrpc.com/cors)
[![GoDoc](https://pkg.go.dev/badge/connectrpc.com/cors.svg)](https://pkg.go.dev/connectrpc.com/cors)

`connectrpc.com/cors` provides convenience methods to make configuring
Cross-Origin Resource Sharing (CORS) easier for
[Connect](https://github.com/connectrpc/connect-go) servers. CORS is often
required for the Connect and gRPC-Web protocols to work correctly in web
browsers.
`connectrpc.com/cors` simplifies Cross-Origin Resource Sharing (CORS) for
[Connect](https://github.com/connectrpc/connect-go) servers. CORS is usually
required for the Connect and gRPC-Web protocols to work correctly in
web browsers.

For background, more details, and best practices, see [Connect's CORS
documentation](https://connectrpc.com/docs/cors).

## Example

This package should work with any CORS package. As an example, we'll use it
with [github.com/rs/cors](https://github.com/rs/cors).
This package should work with any CORS implementation. As an example, we'll use
it with [github.com/rs/cors](https://github.com/rs/cors).

```go
import (
connectcors "connectrpc.com/cors"
"github.com/rs/cors"
connectcors "connectrpc.com/cors"
"github.com/rs/cors"
)

// withCORS adds CORS support to a Connect HTTP handler.
func withCORS(connectHandler http.Handler) http.Handler {
c := cors.New(cors.Options{
AllowedOrigins: []string{"https://acme.com"}, // replace with your domain
AllowedMethods: connectcors.AllowedMethods(),
AllowedHeaders: connectcors.AllowedHeaders(),
ExposedHeaders: connectcors.ExposedHeaders(),
c := cors.New(cors.Options{
AllowedOrigins: []string{"https://acme.com"}, // replace with your domain
AllowedMethods: connectcors.AllowedMethods(),
AllowedHeaders: connectcors.AllowedHeaders(),
ExposedHeaders: connectcors.ExposedHeaders(),
MaxAge: 7200, // 2 hours in seconds
})
return c.Handler(connectHandler)
})
return c.Handler(connectHandler)
}
```

Expand Down

0 comments on commit 9c2a800

Please sign in to comment.