From 915d471b8d9e58888a7abd2c55d67bf33f224f71 Mon Sep 17 00:00:00 2001 From: CarterPerez-dev Date: Sun, 17 May 2026 17:37:36 -0400 Subject: [PATCH] =?UTF-8?q?fix(canary):=20vite=20dev=20proxy=20=E2=80=94?= =?UTF-8?q?=20correct=20backend=20port=20+=20stop=20stripping=20/api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two latent template-leftover bugs in vite.config.ts proxy that 404'd every useTokenTypes/useCreateToken/useManageToken/useDeleteToken call: - Default target was http://localhost:8000. Backend listens on :8080 (backend/config.yaml `server.port: 8080`, default registered in internal/config/config.go). Off-by-one-port silent for the whole Phase 14 cycle because Phase 14 didn't end-to-end-test. - `rewrite: (p) => p.replace(/^\/api/, '')` stripped /api before forwarding. But backend mounts routes UNDER /api via `r.Route("/api", ...)` (cmd/canary/main.go:322). So a request for /api/tokens/types got rewritten to /tokens/types, which backend doesn't serve — 404 page not found. Frontend axios uses baseURL `/api` and path `/tokens/types` → full URL `/api/tokens/types`. With these fixes the proxy now passes that through verbatim to http://localhost:8080/api/tokens/types, which is where chi actually mounts the route. dev.compose.yml: added VITE_API_TARGET=http://canary:8080 to the frontend container's env so the dev-compose path also works (inside the container "localhost" is the vite container, not the canary container — has to use docker DNS). Surfaced today when the operator manually eyeballed the landing page and SpeciesSection rendered "Could not load species catalog. Try again in a moment." (the descriptorsError branch in landing/index.tsx SpeciesSection). --- PROJECTS/beginner/canary-token-generator/dev.compose.yml | 3 ++- .../beginner/canary-token-generator/frontend/vite.config.ts | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/PROJECTS/beginner/canary-token-generator/dev.compose.yml b/PROJECTS/beginner/canary-token-generator/dev.compose.yml index b3aa6c40..a4054b44 100644 --- a/PROJECTS/beginner/canary-token-generator/dev.compose.yml +++ b/PROJECTS/beginner/canary-token-generator/dev.compose.yml @@ -13,7 +13,7 @@ services: image: nginx:1.27-alpine container_name: ${APP_NAME:-canary-token-generator}-nginx-dev ports: - - "${NGINX_HOST_PORT:-58495}:80" + - "${NGINX_HOST_PORT:-22784}:80" volumes: - ./infra/nginx/nginx.conf:/etc/nginx/nginx.conf:ro - ./infra/nginx/dev.nginx:/etc/nginx/conf.d/default.conf:ro @@ -38,6 +38,7 @@ services: - frontend_modules:/app/node_modules environment: - VITE_API_URL=${VITE_API_URL:-/api} + - VITE_API_TARGET=${VITE_API_TARGET:-http://canary:8080} - VITE_APP_TITLE=${VITE_APP_TITLE:-Canary Token Generator} - VITE_TURNSTILE_SITE_KEY=${VITE_TURNSTILE_SITE_KEY:-} networks: diff --git a/PROJECTS/beginner/canary-token-generator/frontend/vite.config.ts b/PROJECTS/beginner/canary-token-generator/frontend/vite.config.ts index a4ad5b31..02260068 100644 --- a/PROJECTS/beginner/canary-token-generator/frontend/vite.config.ts +++ b/PROJECTS/beginner/canary-token-generator/frontend/vite.config.ts @@ -32,9 +32,8 @@ export default defineConfig(({ mode }) => { host: '0.0.0.0', proxy: { '/api': { - target: env.VITE_API_TARGET || 'http://localhost:8000', + target: env.VITE_API_TARGET || 'http://localhost:8080', changeOrigin: true, - rewrite: (p) => p.replace(/^\/api/, ''), }, }, },