0

I am making a custom lightning component in which i am rendering a React app using lightning:container. In that react app i have to make ajax calls to another domain api.xyz.com to fetch and update the data.

Are these cross domain api calls possible somehow? Because the iframe in which lightning:container renders the react app has its src set to something else. I have looked over forums and documentation but unable to come to a conclusion. Please help. Any example will help.

2
  • 1
    Have you tried adding the api.xyz.com domain as a CSP Trusted Site? Are you getting any particular errors in the browser's dev console? I'm also assuming that your react app is stored as a static resource on Salesforce and rendered from there.
    – Kyle
    Commented Feb 13, 2019 at 16:55
  • yes did that only once i found out about CSP trusted sites on salesforce. worked after that. please add this as an answer. will accept and close.
    – ghostCoder
    Commented Feb 18, 2019 at 7:59

1 Answer 1

1

Since you are making an API call to the external domain api.xyz.com you need to add it as a CSP Trusted Site or Salesforce will block it. That will tell Salesforce to add the appropriate directives to the page's CSP headers, thereby allowing you to make cross-domain requests. You'd also need to do this if you were trying to load images, fonts, or styles (but NOT javascript, which needs to be in a static resource) from an external site.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .