Next.js Discord

Discord Forum

Unable to Fetch Data from Backend Server in Next.js SSR Production with Docker

Unanswered
Carolina Dog posted this in #help-forum
Open in Discord
Carolina DogOP
- Frontend: Next.js
- Backend: Express.js

While using Docker and running a Next.js server, I'm unable to fetch data from the backend server during Next SSR (Server-Side Rendering) in production. This issue does not occur during SR (Server-Side Rendering) in development or when using CSR (Client-Side Rendering).

- CSR:
- Development: Fetch works
- Production: Fetch works
- SSR:
- Development: Fetch works
- Production: Fetch fails

I initially encountered errors with SSR in development when using 'http://localhost:8080/' to fetch data from the backend. Using the command docker exec -it next curl http://localhost:8080/ resulted in an error. Switching to docker exec -it next curl http://express:8080 worked, so I updated the link to 'http://express:8080'. However, this solution does not resolve the SSR issue in production. Fetching from '172.88.0.3:8080', the backend container IP, also fails in SSR production.

Both the server and frontend work fine when accessed via a local browser at "http://localhost:3000" and "http://localhost:8080". Inside the Next.js container, curl http://express:8080 receives a response from the Express server.

- Error occurs only during SSR in production.

Error Project Repo : "https://github.com/officialCaesardev/next-js-ssr-issue"

1 Reply

Carolina DogOP
i make some Debugging i included those to that "https://github.com/officialCaesardev/next-js-ssr-issue" please check.