Under my angular App , i'm using renderer2 to load some javascript ressources by injecting them to the head of window
That s working fine but ;
When serving locally , this loading the ressource fails since there is a CORS problem :
Access to XMLHttpRequest at 'https://website/src/style1.css' from origin 'http://192.168.244.128:3001' has been blocked by CORS policy: Request header field x-requested-with is not allowed by Access-Control-Allow-Headers in preflight response.
Note : i'm running my Angular app in my local machine but i'm using some url redirection since it's a vmware virtual machin , that's why my local url is : http://192.168.244.128:3001
I ve tried to use an Angular proxy like this :
proxy.conf.json :
{
"/*": {
"target": "https://website/src/style1.css",
"secure": false,
"changeOrigin": true,
"logLevel": "debug"
}
}
But the problem persists
Suggestions ??
target should be a domain server + port but not a direct resource path
"target": "https://{domain}:{port}"
I also advice you to use a url keyword to identify external requests (in my sample below i choose "resources")
For sample if you want to access
https://website/src/style1.css
you have to access it by
localhost:{localport}/resources/src/style1.css
or resources/src/style1.css
here a proxy config
{
"/resources/*": {
"target": "https://website",
"secure": false,
"changeOrigin": true,
"pathRewrite": {
"^/resources": ""
},
"logLevel": "debug"
}
}