Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions frontend/.env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Frontend API base URL (single source of truth used by src/api.ts)
VITE_API_BASE_URL=http://127.0.0.1:8000
# Backend API origin used by frontend requests (no trailing slash)
VITE_API_URL=http://127.0.0.1:8000
21 changes: 21 additions & 0 deletions frontend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,27 @@ React + Vite frontend for the EDMS backend.
- Mark READY / Abandon / Merge to Plant from project detail
- Document search (`/documents` and `/documents/search`)

## Environment configuration

Set `VITE_API_URL` to your backend origin (no trailing slash). The frontend now reads this value for all API requests.

```bash
cd frontend
cp .env.example .env
# local backend example
VITE_API_URL=http://127.0.0.1:8000
```

If `VITE_API_URL` is missing, the app logs a clear `console.error` and falls back to same-origin requests.

### Vercel setup

In the Vercel frontend project, add:

- `VITE_API_URL=https://gitplant-backend.vercel.app`

Then redeploy so auth/login requests target the deployed backend.

## Run locally
```bash
cd frontend
Expand Down
16 changes: 13 additions & 3 deletions frontend/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,19 @@ import type {
WorkingRevisionStatusResponse,
} from "./types";

const API_BASE_URL =
(import.meta as ImportMeta & { env?: Record<string, string | undefined> }).env
?.VITE_API_BASE_URL ?? "http://localhost:8000";
const frontendEnv = (import.meta as ImportMeta & {
env?: Record<string, string | undefined>;
}).env;

const configuredApiUrl = frontendEnv?.VITE_API_URL?.trim();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve backward compatibility for API env variable

Reading only VITE_API_URL introduces a silent regression for existing deployments that still define VITE_API_BASE_URL (the previously documented key): after upgrading, configuredApiUrl becomes empty and the code falls back to window.location.origin, so auth/API calls are sent to the frontend origin and fail whenever frontend and backend are on different hosts. Please support both names during migration (e.g., prefer VITE_API_URL but fall back to VITE_API_BASE_URL) to avoid breaking current environments.

Useful? React with 👍 / 👎.

const API_BASE_URL = configuredApiUrl || window.location.origin;

if (!configuredApiUrl) {
console.error(
"[api] Missing required VITE_API_URL. Falling back to same-origin requests. " +
"Set VITE_API_URL to your deployed backend URL (for example, https://gitplant-backend.vercel.app).",
);
}

function getAuthHeaders(token: string): HeadersInit {
return { Authorization: `Bearer ${token}` };
Expand Down