Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

496
Visualizações
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 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

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 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda