WHY DOES A PAYMENT PROVIDER'S API REJECT MY PREFLIGHT REQUEST FROM A REACT APP ON LOCALHOST:5173?

apicorsjavascript4 replies · 320 views · started
  1. ugh. everything worked on my machine. Deployed a React app on localhost:5173, and now calls to a payment providers API fail with a CORS error:

    The preflight OPTIONS request seems to fail before the real request is even sent. Im sending an Authorization haeder and JSON content type, if that matters. Id love to understand what changed bteween local and production. Any explanation of what the browesr is doing here would be really helpful. any ideas??

    2
  2. wait what status code does teh OPTIONS preflight request get in teh Network tab?

    0 1 helpful
  3. yeahhh CORS is enforced by the browser, not teh server, which is why Postman and curl work lol the fix is always on the server: it must anwser with Access-Control-Allow-Origin matching your site's origin. Adding headers to your fetch call can't fix it, and mode: 'no-cors' just gives you an unreadable opaque response. fingers crossed 🤞

    2 6 helpful
  4. ahh classic requests with Authorization headers or Content-Type: application/json trigger a preflight OPTIONS request. the server must respond to it with a 2xx status plus Access-Control-Allow-Methods and Access-Control-Allow-Headers listing what u send, many servers return 404 or 401 to OPTIONS, which fails the whole thing. good luck man!

    thinking

    2 2 helpful

Reply to this topic

Sign in or create an account to reply.