Fix Angular2 CORS redirects with Zone

576 views Asked by At

I was connecting my app with a REST API in which some operations return response redirects. So I got the error: "Redirects form [url] has been blocked by CORS policy. Request requires preflight, which is disallowed to follow cross-origin redirect."

Is it possible to create a new zone (besides angular zone and default zone), catch the error and execute the request manually?

Or... any good idea? The server sometimes return redirect responses.

UPDATE:

Flow:

  1. I request the url /foo.
  2. CORS send a OPTIONS request to /foo
  3. When step 2 return ok, then send GET to /foo
  4. The server returns a redirect to /bar

The current flow is:

  1. The browser throws an exception

The flow I want to get:

  1. Catch the exception with zone
  2. Read the url to redirect and launch another GET request to /bar

I think using Zone is possible catch the browser exception. The question is HOW?

I'm not sure if I launch an http request out of angular zone and if everything can become unstable. Do you think this could be possible to do?

0

There are 0 answers