Cross-domain request in SPFx

Iron Contributor

How can I make a cross-domain request in a Client Side Web Part built with the SharePoint Framework? My need is to access SharePoint 2016 data from a SharePoint 2016 site in another domain (same credentials).

 

I found a crossDomainWeb method in the documentation for the add-in model, but nothing for SPFx.

2 Replies

@Christophe Humbert SharePoint 2016 doesn't provide an easy way to configure CORS to allow for cross-domain calls. Easiest way in my experience is to create a custom Web API to perform and expose the SharePoint operations required and host it in the domain where your SPFx components reside. 

 

@Christophe Humbert 

You can use the Dev PnP JS library in SPFx to make cross-site collection calls. 
The setup is very straight forward and will help you with other complex REST API calls as well. 

 

https://pnp.github.io/pnpjs/documentation/getting-started/

https://github.com/SharePoint/PnP-JS-Core/wiki/Configurationexample1.png