How to call a servlet which is deployed inside AEM 6.2 from an application hosted on node server?

Avatar

Avatar

sbg19

Avatar

sbg19

sbg19

30-12-2020

I have a servlet exposed through a path param 

@SlingServlet(paths = { "/exampleservlet" }, methods = {"GET"})

 

when I try to make a fetch call(GET) from my React Js front end layer hosted on node server, AEM is not allowing me to reach the servlet and I get a CORS policy exception in my browser console.

 

Any kind of assistance or suggestions would be appreciated.

Thank you.

 

AEM 6.2 servlet
View Entire Topic

Avatar

Avatar

kunal23

MVP

Avatar

kunal23

MVP

kunal23
MVP

30-12-2020

Yes the request to servlet will be blocked as it is originated from an external application with a different domain. To make this work you will have to register the domain of the external application in AEM CORS OSGI configuration and bind it to the servlet path. Once you configure CORS then AEM will send appropriate response headers to the browser and the browser will be allowed to make the request. 

 

Also, you will have to enable caching of headers in dispatcher if you are caching the response of the servlet in the dispatcher. 

 

For more details please see these URLs- 

https://experienceleague.adobe.com/docs/experience-manager-learn/foundation/security/understand-cros...

https://experienceleague.adobe.com/docs/experience-manager-learn/foundation/security/develop-for-cro...