MCPcopy Create free account
hub / github.com/go-chi/cors

github.com/go-chi/cors

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.2.1 ↗ · + Follow · compare 2 versions

CORS net/http middleware for Go

40 symbols 117 edges 5 files ⚖ MIT 15 documented · 38% ● updated 59d ago★ 42310 open issues

Browse by type

⨍ Functions 35◇ Types & classes 5
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

CORS net/http middleware

go-chi/cors is a fork of github.com/rs/cors that provides a net/http compatible middleware for performing preflight CORS checks on the server side. These headers are required for using the browser native Fetch API.

This middleware is designed to be used as a top-level middleware on the chi router. Applying with within a r.Group() or using With() will not work without routes matching OPTIONS added.

Usage

func main() {
  r := chi.NewRouter()

  // Basic CORS
  // for more ideas, see: https://developer.github.com/v3/#cross-origin-resource-sharing
  r.Use(cors.Handler(cors.Options{
    // AllowedOrigins:   []string{"https://foo.com"}, // Use this to allow specific origin hosts
    AllowedOrigins:   []string{"https://*", "http://*"},
    // AllowOriginFunc:  func(r *http.Request, origin string) bool { return true },
    AllowedMethods:   []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
    AllowedHeaders:   []string{"Accept", "Authorization", "Content-Type", "X-CSRF-Token"},
    ExposedHeaders:   []string{"Link"},
    AllowCredentials: false,
    MaxAge:           300, // Maximum value not ignored by any of major browsers
  }))

  r.Get("/", func(w http.ResponseWriter, r *http.Request) {
    w.Write([]byte("welcome"))
  })

  http.ListenAndServe(":3000", r)
}

Credits

All credit for the original work of this middleware goes out to github.com/rs.

Core symbols most depended-on inside this repo

browse all functions →

Shape

Function 26
Method 9
Struct 3
FuncType 1
Interface 1

Languages

Go100%

Modules by API surface

cors.go14 symbols
utils.go5 symbols
_example/main.go2 symbols

For agents

$ claude mcp add --transport http codehub https://codehub.bot/mcp

One hosted endpoint, no key: your agent can search, read and trace go-chi/cors and every other graph here. Cursor, Windsurf and other clients →

⬇ download graph artifact

Ask about this repo answers extend the page