I'm currently writing a restful web server, that I would like to test from angular2 frontend. Since the server is hosted on another domain while developing I need Access-Control-Allow-Origin: *
(I think). I tried to achieve that by using the gorilla handlers package, namely the following:
origins := handlers.AllowedOrigins([]string{"*"})
log.Fatal(http.ListenAndServe(":"+os.Getenv(util.Port),
handlers.LoggingHandler(os.Stdout, handlers.CORS(origins)(router))))
now when trying to request the server using the following curl:
curl -H "Origin: http://example.com" \
-H "Access-Control-Request-Method: POST" \
-H "Access-Control-Request-Headers: X-Requested-Width" \
-X OPTIONS --verbose localhost:8000
I get an OPTIONS request on the server, which returns 403. I have also tried adding headers and allowed methods:
handlers.AllowedHeaders([]string{"X-Requested-With"})
handlers.AllowedMethods([]string{"GET", "POST", "PUT", "OPTIONS"})
but it made no difference. How can I resolve this?