Forum Discussion
Facing CORS issue when Embeding Power BI in Salesforce Org
Hello Team,
Facing issue while calling loginPopup() api and getting error CORS.
Need immidiate Solution.
1 Reply
- AnonymousNot applicable
Regarding the issue you raised, my solution is as follows:
1.First, you can try to install and enable CORS on the gateway API side with the following command:
npm install corsMultiple routing files:
const express = require("express"); const router = express.Router(); const cors = require("cors"); router.use(cors());Single route file:
const express = require("express") const app = express() const cors = require("cors") app.use(cors())Below are links to related questions:
javascript - React component has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource - Stack Overflow
Here is a link to enable CORS on the gateway API side:
CORS for REST APIs in API Gateway - Amazon API Gateway
2.Second, you can also redefine the headers and return:
const headers = {'Content-Type':'application/json', 'Access-Control-Allow-Origin':'*', 'Access-Control-Allow-Methods':'POST,PATCH,OPTIONS'} const response = { statusCode: 200, headers:headers, body: JSON.stringify(X), }; return response;Here are the links to related questions:
aws lambda - Access to fetch at '' from origin '' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource - Stack Overflow
3.Finally, you can also try adding mode: 'no-cors' to the fetch method:
fetch(clientConfiguration['communitiesApi.local'], { mode: 'no-cors' }) .then((response) => { return response.json(); }) .then(data => { console.log(data); let communitiesFromApi = data.map(community => { return { value: community, display: community } }); this.setState({ communities: [{ value: '', display: 'Select a Community...' }].concat(communitiesFromApi) }); }).catch(error => { console.log(error); });Here are the links to related questions:
javascript - React component has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource - Stack Overflow
Of course, if you have any new ideas, you are welcome to contact us.
Best Regards,
Leroy Lu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.