go-chi / cors

CORS net/http middleware for Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CORS isn't work

grtfou opened this issue · comments

I try the sample code

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

	// Basic CORS
	cors := cors.New(cors.Options{
		AllowedOrigins:   []string{"https://foo.com"},
		AllowedMethods:   []string{"POST", "OPTIONS"},
		AllowedHeaders:   []string{"Accept", "Authorization", "Content-Type", "X-CSRF-Token"},
		ExposedHeaders:   []string{"Link"},
		AllowCredentials: true,
		MaxAge:           300,
	})
	r.Use(cors.Handler)

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

	http.ListenAndServe("127.0.0.1:3000", r)
}
$ curl -H "Origin: http://example.com" http://localhost:3000/
welcome     # ?

Doesn't any setting I lost?

Thank you. :)