Getting response from a RESTful Go service

Hi Community.
So, i have been trying to request from my Go service using Ajax/fetch with the kibana plugin Js file but so far no luck. I get a 405 (method not allowed) error.

request:
fetch('https://somelink/createinfo', { mode: 'no-cors'}, { headers: { 'Content-Type': 'application/json' }, method: "POST", body: jsonsjson }) .then(res => res.text()) .then(console.log)

On Go service I have added the following header.

w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Max-Age", "3600")
w.Header().Set("Access-Control-Allow-Credentials", "true")
w.Header().Set("Access-Control-Allow-Headers", "Access-Control-Allow-Headers, Access-Control-Allow-Methods, Origin,Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers")
w.Header().Set("Access-Control-Allow-Methods", "GET,HEAD,OPTIONS,POST,PUT,DELETE")

The service responds just fine on POSTMAN with no additional headers. Also, the setup is present on k8s and I am using ingress to expose the service securely.

Any help here wil be great. thanks!

I believe you will need the mode set to cors instead of no-cors.

Hi Josh thanks for the response.
I am now using XMLHttpRequest() will end to end cors enabled and that works fine. It even worked with an insecure connection unlike the ajax call.

Thanks!

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.