Fix frontend API URL - use localhost instead of Docker DNS

The frontend container serves static files to the browser on the host machine.
When the browser makes HTTP requests from JavaScript, it runs in the host context,
not the Docker container context. Therefore it needs to use localhost:8000,
not api:8000 (which only works from inside Docker containers).

Changed: API_BASE_URL from 'http://api:8000' to 'http://localhost:8000'

This fixes the 'net::ERR_NAME_NOT_RESOLVED' error when trying to reach the API.

Co-authored-by: Copilot <[email protected]>
This commit is contained in:
John Patrick TeruelandCopilot committed 2026-04-24 21:06:59 +08:00
1 parent 53afc9e59f
commit 6749318253
2 files changed
+4 -4

No files matched your search

+2 -2
View File
@@ -88,10 +88,10 @@ services:
retries: 5 retries: 5
environment: environment:
- NODE_ENV=production - NODE_ENV=production
- VITE_API_URL=http://api:8000 - VITE_API_URL=http://localhost:8000
restart: unless-stopped restart: unless-stopped
# NOTE: All services now run in Docker on the same network # NOTE: All services now run in Docker on the same network
# Frontend: http://api:8000 (Docker service name resolution) # Frontend: http://localhost:8000 (Docker service name resolution)
# Consumer: Still runs on host, connects to kafka:29092 # Consumer: Still runs on host, connects to kafka:29092
volumes: volumes:
+2 -2
View File
@@ -28,8 +28,8 @@ interface Result {
timestamp: string; timestamp: string;
} }
// Default to Docker API service name (will be overridden by environment variable if needed) // Use localhost when browser accesses from host machine
const API_BASE_URL = 'http://api:8000'; const API_BASE_URL = 'http://localhost:8000';
const App: React.FC = () => { const App: React.FC = () => {
const [auth, setAuth] = useState<AuthState>({ const [auth, setAuth] = useState<AuthState>({