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.
Asked
Active
Viewed 6,520 times
0

sideshowbarker
- 81,827
- 26
- 193
- 197

Lucas Kuratani
- 21
- 1
- 4
-
1Have you tried proxying the API requests as described here: https://create-react-app.dev/docs/proxying-api-requests-in-development/ – Shawn Yap Nov 06 '20 at 21:36
-
1Is `cors` enabled in `adonis.js`? – danish-khan-I Nov 07 '20 at 07:06
2 Answers
0
I fixed the issue by changing the AdonisJS cors config file. I switched the origin value from true to *.

Lucas Kuratani
- 21
- 1
- 4
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