Connecting frontend and backend in codespaces?

Hi!

Is there a way to connect my React app to my Nodejs(Express) backend in codespaces? I’m running both in codespaces on different ports and I can access both in my browser but when my React app doesn’t seem to see the backend (timeout). I’m aware that these tunneled URLs use github auth to work in the browser. But developing such architecture is very common so I’m assuming this should be possible.

Thanks. :slightly_smiling_face:

Just to make sure I understand the scenario correctly: Is your frontend trying to connect to your backend from the client-side of the frontend or the server-side of the frontend?

You should be able to do client-side calls to the backend today since your browser is authenticated to both the frontend and backend codespaces, but server-side calls from the frontend container to the backend container in a different codespace won’t work out of the box. We are working on allowing you to open up the ports as “public ports” instead of “private ports”, which would remove the auth on the url. That would enable this scenario for server-to-server calls across multiple codespaces. Until that is available, you could try a couple other options:

  1. Run both services in the same codespace
  2. Use a different proxying solution for the backend service to expose it on a public url, such as ngrok

Hey! Thanks for your answer. I investigated more and I realized I was having CORS issues. I was able to solve it finally but for future searches I’m leaving here my example repository:

Thanks again! Have a nice day!