0

I am trying to access the backend using this query

fetch("<backend-server-link>", {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
        Token: <token>,
      },
      body: JSON.stringify(payload),
    })

But I get this error in my console.

Access to fetch at '< site-name>' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: Redirect is not allowed for a preflight request.

The backend is hosted on a AWS server. The backend code is in Python an Flask, and I have included CORS in the Flask app. How do I resolve this error?

I tried adding the 'no-cors' mode in the fetch query but it did not work.

  • You might want to check in the network tab of the browser dev tools if there is an OPTIONS request before the actual request to the API (preflight request) that gets redirected (3xx status code) for some reason (e.g. from `http://` to `https://`?) – zilam Jan 02 '23 at 13:16

0 Answers0