contenta_react_next
contenta_react_next copied to clipboard
Switch backend url
Hi! This is not an issue but rather a question. I am successfully running the recipe demo locally and also the contenta cms both in docker.
I would like to connect the contenta_react_next to my local contenta cms to retrieve the recipes from the content there.
I have tried to accomplish this by changing the BACKEND_URL in my .env file and then doing make install and make up but the react interface still gets the content from the remote cms.
What must I do to get this working?
Hi @bjarman, basically, all you need to do is to change the BACKEND_URL
in .env
file and then run make down
following by make up
, no need to reinstall the project. It should work!
I have tried this but the content is still fetched from https://live-contentacms.pantheonsite.io/api/recipes and not from my local cms. Could this be a docker issue? How should the BACKEND_URL look for the conecta_react_next container to reach my contenta_cms container? I can reach them both using "localhost" but on different ports. But can one container actually reach the other using localhost?
Hm, that's the only place that holds the URL of the backend. Alright, try docker-compose down
and then make up
again. Also, make sure you're modifying the value of .env
and not .env.default
file.
..actually. The BACKEND_URL is set in package.json - this is where i have made changes like so: "env": { "BACKEND_URL": "http://localhost:84", "JSONAPI_PREFIX": "/api" }
Both containers are on my localhost, on different ports, but are the containers aware of each other is what I mean. A container issue rather than an issue with react or cms?
In package.json the env vars are just for now.sh environment, it does not affect your local environment.
There is no BACKEND_URL variable in .env file. Should I add it manually?
Are you sure you're looking at reactjs/.env
and not the .env
in the root of the repo?
I have changed there as well but no change. Content is still from remote cms.
what's the output if you log into the container with docker-compose exec node bash
and then echo $BACKEND_URL
?
That echoes nothing. However looking in the .env file from within the container it has the correct BACKEND_URL. Very strange.
Looks like you have some issues with your local set up. Not sure if I can help here, it requires a bit of debugging on your local.
But how come that even though the .env file has the correct url but still gets the content from the live.contentacms site? That should be impossible right?
I will start over with my local environment from scratch and see what happens. Still a bit mysterious though. If you leave this issue open for a few days I will post back and let you know how it turns out and if I find out what was wrong.
I've got the react frontend spun up working great but cant figure out how to point to my local backend, I've scanned code for pantheon, replaced every URL, run make down, make install, make up and it's still connecting to pantheon, can you help?
@timrabbetts as far as I recall, you need to change the URL in the .env file in the root of the repository and then restart the environment (make restart
).