CodeForPhilly / CodeForPhilly/balancer-main

Local development frontend API calls failing

Open
#446 0 comments 0 reactions 1 assignee Claimed by @sahilds1 View on GitHub
Bug
Dominant language
TypeScript
Stars
21
Forks
19
PR merge metrics
No merged PRs in 30d

Description

## Steps to Reproduce
1. Start local Docker environment: `docker compose up`
2. Navigate to frontend at `http://localhost:3000`
3. Trigger any API call (e.g., fetch medication list)
4. Observe error in browser console and Vite terminal

## Possible Fix: Vite proxy

### Background

The API client uses relative URLs (/api/...), so requests go to the frontend's origin unless a proxy forwards them to the backend. In development, Vite runs a Node.js server that serves the React app and can proxy requests. In production, Vite compiles React into static files served by nginx or a CDN — the infrastructure handles API routing instead.

### Fix

Add a proxy to frontend/vite.config.ts:

```
  server: {
    proxy: {
      '/api': {
        target: 'http://backend:8000',
        changeOrigin: true,
      },
    },
  },
```

Rebuild with docker compose down && docker compose up --build.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.