contenta_react_next icon indicating copy to clipboard operation
contenta_react_next copied to clipboard

Switch backend url

Open bjarman opened this issue 5 years ago • 15 comments

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?

bjarman avatar Nov 04 '19 11:11 bjarman

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!

spleshka avatar Nov 04 '19 11:11 spleshka

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?

bjarman avatar Nov 04 '19 12:11 bjarman

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.

spleshka avatar Nov 04 '19 12:11 spleshka

..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?

bjarman avatar Nov 04 '19 12:11 bjarman

In package.json the env vars are just for now.sh environment, it does not affect your local environment.

spleshka avatar Nov 04 '19 12:11 spleshka

There is no BACKEND_URL variable in .env file. Should I add it manually?

bjarman avatar Nov 04 '19 12:11 bjarman

Are you sure you're looking at reactjs/.env and not the .env in the root of the repo?

spleshka avatar Nov 04 '19 12:11 spleshka

I have changed there as well but no change. Content is still from remote cms.

bjarman avatar Nov 04 '19 12:11 bjarman

what's the output if you log into the container with docker-compose exec node bash and then echo $BACKEND_URL ?

spleshka avatar Nov 04 '19 12:11 spleshka

That echoes nothing. However looking in the .env file from within the container it has the correct BACKEND_URL. Very strange.

bjarman avatar Nov 04 '19 12:11 bjarman

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.

spleshka avatar Nov 04 '19 12:11 spleshka

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?

bjarman avatar Nov 04 '19 12:11 bjarman

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.

bjarman avatar Nov 04 '19 13:11 bjarman

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?

ghost avatar Mar 24 '22 07:03 ghost

@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).

spleshka avatar Mar 24 '22 07:03 spleshka