I have a local react application that through axios calls a route on (GET) forestadmin implemented on a middleware.
retrieves some data and makes a post on the forestadmin database.
unfortunately it doesn’t work and gives me the following error:
Blocked multi-origin request (cross-origin): the origin match criterion does not allow reading of the remote resource from https://website.com Reason: missing CORS “Access-Control-Allow-Origin” header.
The forestadmin application is on heroku and the CROSS_ORIGINS variable is present.
yes correct I need another site to make a GET call on a public route but also a POST call where I have to register the user.
Currently the GET call is in middleware
ok then I try to add the variable on heroku (the forest admin app resides there remotely for staging) the origin POST localhost:3000 since I am developing locally and then I will change with the remote domain.
I tried to insert the variable, on heroku, CORS_ORIGINS = http://localhost:3000
but keep giving me the usual error …
as I said I am calling the endpoint of my forestadmin app from an application in react locally
Could we have a diagram of the call requests you are doing?
If I understand correctly, you have a local react app which make requests to your generated forest admin project.
And this project is hosted on heroku, right?
Did you try to make requests call with your local react app and a local generated forest admin project?
Blocked multi-origin request (cross-origin): the origin match criterion does not allow the remote resource to be read from http://localhost: 3000/invio-form. Reason: missing CORS “Access-Control-Allow-Origin” header.
in my .env file of my forestadmin app I set the variable:
CORS_ORIGINS = http://localhost:3001
Judging by the error, Reason: missing CORS “Access-Control-Allow-Origin” header. is saying that the required header is missing, not that it has an incorrect value.
May I know where you did put your public service (In which file/location)?
Also, if you are trying to call the service from localhost to heroku server, Access-Control-Allow-Origin is required, so that most likely the source of your issue.
Maybe a browser network tabs screenshot on the failing call would help me to better understand the issue here.
I was referring to the code you added on the forest admin backend, not the React one.
The access Access-Control-Allow-Origin header should be on the service response.
To be more specific, you can take a look on any given request of your forestadmin UI done to your backend.
Depending on where you did put this service on your backend, it might not attach the Access-Control-Allow-Origin.
It looks like the missing CORS configuration in the code you shared could be the problem.
It actually depends on the location of this file in your Forest Admin project folder.
Can you share this location to confirm the origin of the issue?
That is not the right place if you want to benefit from the default CORS configuration of your Forest Admin backend.
I think the place to be, for this file, is routes folder (as if you were creating a Smart Action controller, see documentation)