CORS error on Runtime API endpoint

Avatar

Avatar

keilorblend360

Avatar

keilorblend360

keilorblend360

20-02-2020

I'm setting up an API through OpenWhisk with multiple endpoints:


/privacy/jobs/create POST
/privacy/jobs/{jobID} GET
/privacy/jobs/files/{jobID} GET
/privacy/events/  GET and POST


for my POST /jobs/create endpoint, I am getting CORS errors: 

Access to XMLHttpRequest at 'https://runtime.adobe.io/apis/****/privacy/jobs/create' from origin 'https://requestdomain.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.


I can access the endpoint with Postman just fine. To test if it was just a nested endpoint issue, I created a GET /jobs/create endpoint (same endpoint, different method), and am receiving 0 errors accessing directly from the browser. The only difference is that my POST /jobs/create endpoint points to a zip action. My GET /jobs/create does not.

Is there something I'm missing in my zip action? 

I've added access-control headers to my return: 

 

return {
  headers: { 
    'Access-Control-Allow-Origin':'*',
    'Content-Type':'application/json'
  },    
  statusCode: 200,
  body: {
    jobIds: privacy_jobIds
  } 
};


What am I doing wrong here? I can access every other endpoint on the /privacy API just fine.

View Entire Topic

Avatar

Avatar

Mihai_Corlan

Employee

Avatar

Mihai_Corlan

Employee

Mihai_Corlan
Employee

13-04-2020

Hello there,

 

We've updated the docs to cover this topic: https://github.com/AdobeDocs/adobeio-runtime/blob/master/guides/creating_rest_apis.md#enable-cors-on...

 

thank you,

Mihai