1
return this.http.get<any>('https://test.p-44.com/api/v3/tl/shipments/'+id+'/statuses?includeMapUrl=true', {
      headers:
        new HttpHeaders()
          .append('Accept', 'application/json')
          .append('Content-Type', 'application/json')
          .append('Authorization', 'Basic ' + btoa("xxxxx:xxx"))
      , responseType: 'json'
    })
    .map((response: Response) => <any>response)

Here is my service call of the Api, this will return an error :

Failed to load https://test.p-44.com/api/v3/tl/shipments/1252/statuses?includeMapUrl=true: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://dev.18th-avenue.com' is therefore not allowed access. The response had HTTP status code 401.

But this call will work perfectly fine on my locahost when I use a proxy config as :

const PROXY_CONFIG = [
  {
      context: [
          "/44",
      ],
      target: "https://test.p-44.com",
      secure: false,
      changeOrigin: true,
      pathRewrite: {"^/44" : ""}

  }
]
module.exports = PROXY_CONFIG;


return this.http.get<any>('/44/api/v3/tl/shipments/'+id+'/statuses?includeMapUrl=true', {
      headers:
        new HttpHeaders()
          .append('Accept', 'application/json')
          .append('Content-Type', 'application/json')
          .append('Authorization', 'Basic ' + btoa("pmorin@18th-avenue.com:Action18!"))
      , responseType: 'json'
    })
    .map((response: Response) => <any>response)

Do you have any idea why this proxy call works but the one without does not? I use IIS server, do I need to add a config there or something? When I will build my application on my server, I won't be able to use that proxy

Thank you

  • CORS issue - This is a kind of browser security, not related to Angular. Learn more : https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin – Ritwick Dey Apr 27 '18 at 13:44
  • see [this](https://blog.angularindepth.com/deploy-an-angular-application-to-iis-60a0897742e7) and [this](https://juristr.com/blog/2016/11/configure-proxy-api-angular-cli/) – Vikas Apr 27 '18 at 14:32
  • 1
    Possible duplicate of [MVC web api: No 'Access-Control-Allow-Origin' header is present on the requested resource](https://stackoverflow.com/questions/27504256/mvc-web-api-no-access-control-allow-origin-header-is-present-on-the-requested) – David Apr 27 '18 at 16:54

0 Answers0