0

I have a server, in which I'm running two different applications. The frontend (express + React) is running on 443 port, and the AdonisJS api is running on 3333 port. They share the same domain (something.com, for example), but I need to add the port when calling the api. The problem is, when I try to hit an endpoint from my api from React, I get this error: strict-origin-when-cross-origin. Actually, I'm not sure if this is an error, but I can't make any request at all. From another client, such as Insomnia, the request works like magic.

Error in devtools when trying to log in

sideshowbarker
  • 81,827
  • 26
  • 193
  • 197

2 Answers2

0

I fixed the issue by changing the AdonisJS cors config file. I switched the origin value from true to *.

0

Besides adding the proxy instruction in package.json "proxy": "http://localhost:5000", I also had to remove the host from the api url request, so:

const apiData = await axios.get('http://127.0.0.1:5000/api/get-user-data');

became

const apiData = await axios.get('/api/get-user-data');

The link provided by @ShawnYap was really helpful https://create-react-app.dev/docs/proxying-api-requests-in-development/

Diego Benetti
  • 97
  • 1
  • 8