Expand my Community achievements bar.

SOLVED

CORS issue whn sending request from React

Avatar

Level 3

Hi.

I'm trying to send a request to AEM from React. But I get either a CORS error or an empty response with status 200, but from the browser the response has a body.

Tell me how to set it up if:

AEM localhost:4502

React localhost:3000

 

Config

aliaksandr_hvoz_0-1694259645198.png

React fetch

aliaksandr_hvoz_1-1694259671258.png

Thank you very much in advance)

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hello @aliaksandr_hvoz 

 

There is a detailed adobe documentation on how to deal with CORS errors. Please refer to https://experienceleague.adobe.com/docs/experience-manager-learn/foundation/security/understand-cros...

 

One would have to update :

  •  Publish -> "Adobe Granite Cross Origin Resource Sharing Policy" OSGi config to declared allowed origins, methods etc
  • Dispatcher:
    • Allowing CORS request headers
    • Caching CORS resposne headers

 

Even steps for debugging are available on the link

 


Aanchal Sikka

View solution in original post

3 Replies

Avatar

Community Advisor

You may consider adding "Authorization" in the Supported Headers. Please refer to the Site 2 example, which requires authentication. https://experienceleague.adobe.com/docs/experience-manager-learn/foundation/security/understand-cros... 

"supportedheaders":[
  "Origin",
  "Accept",
  "X-Requested-With",
  "Content-Type",
  "Access-Control-Request-Method",
  "Access-Control-Request-Headers",
  "Authorization", // New
  "CSRF-Token" // New
]

 

Avatar

Correct answer by
Community Advisor

Hello @aliaksandr_hvoz 

 

There is a detailed adobe documentation on how to deal with CORS errors. Please refer to https://experienceleague.adobe.com/docs/experience-manager-learn/foundation/security/understand-cros...

 

One would have to update :

  •  Publish -> "Adobe Granite Cross Origin Resource Sharing Policy" OSGi config to declared allowed origins, methods etc
  • Dispatcher:
    • Allowing CORS request headers
    • Caching CORS resposne headers

 

Even steps for debugging are available on the link

 


Aanchal Sikka

Avatar

Administrator

@aliaksandr_hvoz Do you find the suggestions from users useful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. 



Kautuk Sahni