• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

389
Views
Angular : CORS problem when loading external script or ressource

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 ??

about 3 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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"
    }
  }
about 3 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error