enabling CORS for a golang REST app

51 views
Skip to first unread message

gmuth...@gmail.com

unread,
Oct 24, 2017, 6:04:07 PM10/24/17
to google-appengine-go
I have enabled CORS for the golang REST app deployed on GAE. I don't use cloud endpoints. Its a simple app that exposes a GET and a POST api and works fine on POSTMAN. However cannot use any js client to POST because of CORS error. 

I have enabled CORS as below:
httpServer = &http.Server{
Addr: ":8080",
Handler: handlers.CORS(
handlers.AllowedOrigins([]string{"*"}),
handlers.AllowedHeaders([]string{"Authorization", "Access-Control-Allow-Headers"}),
handlers.AllowedMethods([]string{"GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS"}))(router),
ReadTimeout:    timeout,
WriteTimeout:   timeout,
MaxHeaderBytes: 1 << 20,
}
}

Any pointers will help.

gmuth...@gmail.com

unread,
Oct 26, 2017, 5:56:11 PM10/26/17
to google-appengine-go
Update:  I'm using the GAE flex engine and Gorilla Mux as my http middleware.
Reply all
Reply to author
Forward
0 new messages