Search code examples
reactjsresthttp-redirectcorsfetch

POST request fails only on some machines


I've developed a REST web server that handles both a GET and POST route.
My web server is developed in Pharo.
I use a simple .htaccess to redirect everything to my Pharo application.
The REST query is sent to HTTPS (port 443) and redirected to 8079.

RewriteEngine on  
RewriteRule (.*) http://localhost:8079/$1 [P]  

Everyone seems to have work okay with the GET queries.
However, some people have issues with the POST query.
The preflight check seems to be okay for everyone.
However, the POST request itself fails only for some machines/network.
Some people other than me were able to have both the preflight check & the post request working.
I still haven't found any discriminating factors.

Access to fetch at 'https://rest.didyouknowmythicplus.com/sug' from origin 'https://deplete.fyi' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
index-40151e28.js:90 
POST https://rest.didyouknowmythicplus.com/sug net::ERR_FAILED 307 (Temporary Redirect)

I do not know why I have a temporary Redirect, could it be because of the .htaccess proxy?

Although the error message talks about CORS, it seems to me that it's not the issue.
In the errored case, the POST request doesn't seem to get to the Pharo webserver.
If the Pharo web server doesn't get the request, it cannot add the CORS to the answer.

The backend is a vite/react application that uses a fairly simple fetch:

fetch(postUrl, {
  method: "POST",
  body: JSON.stringify({someData}),
  headers: {
    "Content-type": "application/json; charset=UTF-8",
  }
})

Any idea of what could be causing the POST request to be mishandled only for some machines/networks? I don't have any other ideas left myself.

I tried many things, particularly:

  • Confirmed that the POST request wasn't getting to the webserver;
  • Tried many CORS tweaks of all kind (client, web server, htaccess);
  • Tried multiple tweaks of the fetch;
  • Tried multiple tweaks of the webserver routes (like keeping only the post route);
  • Tried multiple tweaks of the .htaccess.
  • Tried to put my rest on the same domain as the react application, but I had some ssl issues.

Related question: Was a web server-side error, so this seems different - CORS: Why do I get successful preflight OPTIONS, but still get CORS error with post?


Solution

  • I finally fixed it by using a PUT instead of a POST method I have no idea of how/why it works though :)