Skip to content

Commit

Permalink
Update cors.md to allow CORS for websockets
Browse files Browse the repository at this point in the history
  • Loading branch information
nii236 authored Aug 5, 2019
1 parent 373359d commit ab228f1
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion docs/content/recipes/cors.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,18 @@ func main() {
Debug: true,
}).Handler)

upgrader := websocket.Upgrader{
CheckOrigin: func(r *http.Request) bool {
// Check against your desired domains here
return true
},
ReadBufferSize: 1024,
WriteBufferSize: 1024,
}

router.Handle("/", handler.Playground("Starwars", "/query"))
router.Handle("/query",
handler.GraphQL(starwars.NewExecutableSchema(starwars.NewResolver())),
handler.GraphQL(starwars.NewExecutableSchema(starwars.NewResolver()), handler.WebsocketUpgrader(upgrader)),
)

err := http.ListenAndServe(":8080", router)
Expand Down

0 comments on commit ab228f1

Please sign in to comment.