I am using javascript to render React Component.
Javascript snippet
function loadRemoteComponent(url) {
return fetch(url)
.then(res => res.text())
.then(source => {
var exports = {}
function require(name) {
if (name == 'react') return React
else throw `You can't use modules other than "react" in remote component.`
}
const transformedSource = Babel.transform(source, {
presets: ['react', 'es2015', 'stage-2']
}).code
eval(transformedSource)
return exports.__esModule ? exports.default : exports
})
}
using URL, I am rendering React Component. React component is rendered using Javascript with in current solution / web site.
When I tried to render the Javascript in different web site, it shows me CORS error.
I have tried "Access-Control-Allow-Origin"; but that is not working,
It shows me error in console "Access to fetch at 'http://xxx/Scripts/components/xxx.jsx' from origin 'http://yyy' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled."
Do any one have any solution for this?