Fixing CORS Errors in SPFx with Azure Functions

πŸš€ This article has moved!

Please visit the updated version here:

πŸ‘‰ Go to Updated Article

5 thoughts on “Fixing CORS Errors in SPFx with Azure Functions

  1. i tried code which you provided. but it is gives following error message.

    TypeError: Failed to fetch
    at FetchProvider.UE6e.FetchProvider.fetch (sp-webpart-workbench-assembly_en-us.js:49867)
    at Function.8Y7G.HttpClientHelper.fetchCore (sp-webpart-workbench-assembly_en-us.js:48803)
    at HttpClient.LJZb.HttpClient._fetch (sp-webpart-workbench-assembly_en-us.js:49488)
    at HttpClient.LJZb.HttpClient.fetch (sp-webpart-workbench-assembly_en-us.js:49456)
    at HttpClient.LJZb.HttpClient.get (sp-webpart-workbench-assembly_en-us.js:49469)
    at SpfxCors. (SpfxCors.tsx:58)
    at step (SpfxCors.module.scss.ts:17)
    at Object.next (SpfxCors.module.scss.ts:17)
    at SpfxCors.module.scss.ts:17
    at new Promise ()

    but following code is working for same URL

    let reqUrl = “https://api.darksky.net/forecast/fe01c49b6533f1d7460ed2e82302b5bc/24.4851589,74.8916458?callback=?&units=si”;
    $.getJSON(reqUrl, (data) => {
    console.log(“data :”);
    console.error(data);
    }).catch((jqXHR, textStatus, errorThrown) => {
    console.error(textStatus);
    console.log(textStatus);
    });

    thanks
    navaratan

    Like

Comments