How about selecting the right url dynamically within your application. Sample say.
export const getApiUrl = () => {
if (typeof window === 'undefined') {
// Server
return process.env.SERVER_PYTHON_API;
} else {
// Client
return process.env.NEXT_PUBLIC_PYTHON_API;
}
};
Then when making API calls, use the function to get the correct URL. Sample like
const fetchData = async () => {
const apiUrl = getApiUrl();
const response = await fetch(`${apiUrl}/your-endpoint`);
const data = await response.json();
return data;
};
With this you can work with both URL's. And update docker compose env with both url
environment:
- NEXT_PUBLIC_PYTHON_API=http://localhost:8000
- SERVER_PYTHON_API=http://server:8000