← ClaudeAtlas

dev-environment-patternslisted

Debug and configure local dev-server networking for multi-device access — Vite proxy, env-var URL priority, 0.0.0.0 binding, and WSL2 quirks. Use when API/fetch or WebSocket calls fail from a phone/tablet/other PC ("localhost refused", CORS blocked, NetworkError, WS won't connect), when a server is only reachable from localhost, when a leftover VITE_API_URL breaks dev, or when setting up network access on WSL2.
nxtg-ai/forge-plugin · ★ 5 · AI & Automation · score 73
Install: claude install-skill nxtg-ai/forge-plugin
# Development Environment Patterns Institutional knowledge for local dev-server networking, learned from real forge-ui debugging. All code here mirrors the live config in `forge-ui/vite.config.ts` and `forge-ui/src/services/api-client.ts` (ports: UI 5050 → proxies to API/WS 5051). --- ## Pattern: Multi-Device Development Access **Severity**: Critical (blocks all functionality from non-localhost devices). ### Symptom API/WS calls fail only when accessed from a phone, tablet, or another PC: - `Cross-Origin Request Blocked: localhost:5051` - `NetworkError when attempting to fetch resource` - WebSocket connection failures ### Root cause `localhost` on the remote device points at *that device*, not the dev server. Any URL that names `localhost` (hardcoded or via `VITE_API_URL`) is unreachable off-machine. The fix is relative URLs proxied by Vite, so the browser only ever talks same-origin to whatever host it loaded the page from. ### Correct pattern (matches live source) ```ts // src/services/api-client.ts — env var wins, else relative /api in dev const getApiBaseUrl = () => { if (import.meta.env.VITE_API_URL) return import.meta.env.VITE_API_URL; // prod only if (import.meta.env.DEV) return "/api"; // Vite proxies this const host = typeof window !== "undefined" ? window.location.hostname : "localhost"; return `http://${host}:5051/api`; // prod fallback }; ``` ```ts // vite.config.ts — bind all