79508656

Date: 2025-03-14 09:47:55
Score: 0.5
Natty:
Report link

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
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Starts with a question (0.5): How
  • Low reputation (1):
Posted by: Tobi Akintunlese