rs/cors

Mux and Cors

mazdak78 opened this issue · 1 comments

Thank you for this library.
I use code below to enable cors on my server.

        myRouter := mux.NewRouter().StrictSlash(true)

	myRouter.HandleFunc("/", homePage)
	myRouter.HandleFunc("/all", returnAllArticles)
	
	c := cors.New(cors.Options{
		AllowedOrigins: []string{"https://*.mywebsite.com"},
		Debug: true,
	})

	handler := c.Handler(myRouter)

	port := "8080"
	if os.Getenv("ASPNETCORE_PORT") != "" { // get enviroment variable that set by ACNM
		port = os.Getenv("ASPNETCORE_PORT")
	}

	log.Fatal(http.ListenAndServe(":"+port, c.Handler(handler)))

When I send request to my server, in my debug console, I see these lines which I assume are good:

[cors] 2019/09/30 19:06:50 Handler: Actual request
[cors] 2019/09/30 19:06:50 Actual request no headers added: origin 'http://localhost:53285' not allowed

But the problem is, the code handle the request and it continues to the routes instead of returning back error. What am I missing?

jub0bs commented

Contrary to what you may have read, the purpose of CORS is not to block requests on the server side.