contentacms / contenta_react_next

React + Next.js implementation for Contenta
https://contenta-react-next.now.sh
14 stars 10 forks source link

Switch backend url #11

Open bjarman opened 4 years ago

bjarman commented 4 years ago

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?

spleshka commented 4 years ago

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!

bjarman commented 4 years ago

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?

spleshka commented 4 years ago

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.

bjarman commented 4 years ago

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

spleshka commented 4 years ago

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

bjarman commented 4 years ago

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

spleshka commented 4 years ago

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

bjarman commented 4 years ago

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

spleshka commented 4 years ago

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

bjarman commented 4 years ago

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

spleshka commented 4 years ago

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.

bjarman commented 4 years ago

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 commented 4 years ago

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.

ghost commented 2 years ago

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?

spleshka commented 2 years ago

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