fix: manage.sh must source .env before starting Vite so VITE_API_BASE and VITE_BASE_URL are active #24

Closed
opened 2026-04-12 17:54:55 -07:00 by pyr0ball · 0 comments
Owner

Problem

When manage.sh restart (or the equivalent manual npm run dev) is run without first sourcing .env, Vite starts with no VITE_API_BASE and no VITE_BASE_URL. This causes two silent failures:

  1. Wrong base pathbase: process.env.VITE_BASE_URL ?? "/" falls back to /, so the app serves at root instead of /linnet/. Assets load but the SPA is at the wrong path.
  2. API calls go to wrong prefiximport.meta.env.VITE_API_BASE is empty, so all fetch calls omit /linnet and hit e.g. /session/start instead of /linnet/session/start. Caddy has no route for the unprefixed path → redirects to auth → CORS error → session start fails.

This was discovered 2026-04-13 when a plain npm run dev -- --host 0.0.0.0 --port 8521 started Vite without the env, producing a blank page / CORS failure through the cloud proxy.

Fix

manage.sh start and restart commands must source .env before spawning the Vite process:

set -a; source .env; set +a
conda run -n cf ... uvicorn ...  # backend already does this
npm run dev -- ...               # Vite must inherit the env too

Also verify .env.example exists and is up to date so the cp .env.example .env fallback path in manage.sh works on a fresh clone.

Acceptance

  • bash manage.sh restart starts Vite with VITE_API_BASE=/linnet and VITE_BASE_URL=/linnet/ visible in the process env
  • App loads correctly at https://menagerie.circuitforge.tech/linnet/ after a clean restart with no manual env setup
  • .env.example present and includes VITE_BASE_URL, VITE_API_BASE, CF_ORCH_URL, CF_ORCH_AGENT_URL
## Problem When `manage.sh restart` (or the equivalent manual `npm run dev`) is run without first sourcing `.env`, Vite starts with no `VITE_API_BASE` and no `VITE_BASE_URL`. This causes two silent failures: 1. **Wrong base path** — `base: process.env.VITE_BASE_URL ?? "/"` falls back to `/`, so the app serves at root instead of `/linnet/`. Assets load but the SPA is at the wrong path. 2. **API calls go to wrong prefix** — `import.meta.env.VITE_API_BASE` is empty, so all fetch calls omit `/linnet` and hit e.g. `/session/start` instead of `/linnet/session/start`. Caddy has no route for the unprefixed path → redirects to auth → CORS error → session start fails. This was discovered 2026-04-13 when a plain `npm run dev -- --host 0.0.0.0 --port 8521` started Vite without the env, producing a blank page / CORS failure through the cloud proxy. ## Fix `manage.sh` `start` and `restart` commands must source `.env` before spawning the Vite process: ```bash set -a; source .env; set +a conda run -n cf ... uvicorn ... # backend already does this npm run dev -- ... # Vite must inherit the env too ``` Also verify `.env.example` exists and is up to date so the `cp .env.example .env` fallback path in manage.sh works on a fresh clone. ## Acceptance - `bash manage.sh restart` starts Vite with `VITE_API_BASE=/linnet` and `VITE_BASE_URL=/linnet/` visible in the process env - App loads correctly at `https://menagerie.circuitforge.tech/linnet/` after a clean restart with no manual env setup - `.env.example` present and includes `VITE_BASE_URL`, `VITE_API_BASE`, `CF_ORCH_URL`, `CF_ORCH_AGENT_URL`
pyr0ball added this to the Notation — v0.1.x milestone 2026-04-17 11:56:16 -07:00
Sign in to join this conversation.
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: Circuit-Forge/linnet#24
No description provided.