#Making API from nextjs client side to separate backend in docker setup

3 messages · Page 1 of 1 (latest)

devout bluff
#

I know this question is asked a lot already, but after searching the internet for hours, I still haven't found a solution. In a setup with Docker and two separate backends, one Next.js and one Express, the Next.js server-side can easily access the Express backend through its container name. However, the Next.js client-side cannot do this because the container name is not exposed in the browser environment. Another option is using the host machine and forwarding the ports of both servers to it. The Next.js server can connect to the Express server through 'host.internal.docker,' but this is still only accessible within the Docker context. Therefore, the Next.js client-side won't work with it.

What is the most sensible choice here for calling the API from the Next.js client-side to the Express container? Should I create two API endpoints and switch depending on the environment?

slim relicBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

halcyon steeple