Skip to content

Latest commit

 

History

History
39 lines (29 loc) · 1.55 KB

README.md

File metadata and controls

39 lines (29 loc) · 1.55 KB

cors-examples

What is this?

This repository is a collection of examples that illustrate how to use github.com/jub0bs/cors, a principled CORS middleware library, in conjunction with net/http and popular third-party routers for Go.

What is the example?

The example invariably consists in creating a CORS middleware that

  • allows anonymous access from Web origin https://example.com,
  • with requests whose method is either GET or POST, and
  • (optionally) with request header Authorization,

and applying the middleware in question to all the resources accessible under an /api/ path.

In addition, a /hello path is left unconfigured for CORS.

Which routers are represented?

Library Compatibility Path to example
Chi v5.1+ chi=v5/main.go
Echo v4.11+ echo-v4/main.go
Fiber v2.52+ fiber-v2/main.go
gorilla/mux v1.8+ gorilla-mux/main.go
net/http v1.22+ net-http/main.go