Commit 9958e8e1 authored by Aryan Noshirvnai's avatar Aryan Noshirvnai

Fix dev proxy targeting the box's own public IP instead of loopback

vite.config.ts's BACKEND_PROXY_TARGET defaulted to the machine's public IP
even though vite and the backend always run on the same host - every API
call round-tripped through Hetzner's network via NAT hairpin instead of a
plain loopback call. That's the same network path that already caused a
full outage earlier in this project; it happened to still work here, but
made every request hostage to cloud routing/firewall behavior it never
needed to depend on. Default is now 127.0.0.1, override via
BACKEND_PROXY_TARGET if the backend ever runs elsewhere.

Also documents in .env.example that the dev auto-login token pair is
inherently one-shot (refresh tokens rotate/single-use) and will go stale on
its own - that staleness, not this proxy issue, was what actually produced
"pages take very long to load" (two dead round trips - /auth/me,
/auth/refresh - before bouncing to /login on every fresh page load).
Co-Authored-By: 's avatarClaude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019i3NAUkLkHNbsPg5vKfzF9
parent da534d8e
Pipeline #1082 canceled with stage
# Base URL of the stax_backend_api instance to talk to, and where vite.config.ts's dev-only
# proxy forwards to (see BACKEND_PROXY_TARGET). Point this at the dev server while developing,
# and at prod for a production build.
# Base URL of the stax_backend_api instance to talk to. Point this at the dev server while
# developing, and at prod for a production build.
VITE_API_BASE_URL=http://144.76.210.145:8000
BACKEND_PROXY_TARGET=http://144.76.210.145:8000
# Loopback, not the public IP - vite.config.ts's dev-only proxy runs on the same host as the
# backend, so this should never actually leave the machine. Using the public IP here used to
# "work" only via Hetzner NAT-hairpinning a self-connection back through the same
# firewall/routing path that already caused an outage in this project once; only override this
# with a real remote address if the backend genuinely runs elsewhere.
BACKEND_PROXY_TARGET=http://127.0.0.1:8000
# `npm run dev` runs over https:// (see the basicSsl comment in vite.config.ts), so calling the
# still-http:// backend directly gets blocked as mixed content - route it through the dev
......@@ -14,11 +18,16 @@ BACKEND_PROXY_TARGET=http://144.76.210.145:8000
# Dev-only auto-login (see AuthContext.tsx) - only takes effect under `npm run dev`
# (import.meta.env.DEV), never in a production build, regardless of whether these are set.
# Real, DB-backed tokens for a dedicated dev-test-user row on the dev server, not forged -
# mint your own pair the same way if these ever expire/get revoked:
# PYTHONPATH=. python3 -c "from src.core.security import create_access_token, create_refresh_token; ..."
# (see stax_backend_api conversation history for the exact script that also inserts the
# matching refresh_tokens row - a bare create_refresh_token() call alone won't be accepted by
# /auth/refresh without that row existing).
# Real, DB-backed tokens for a dedicated dev-test-user row (username "dev-test-user",
# super_admin), not forged. These WILL go stale on their own - refresh tokens are
# single-use/rotating by design, so the pair below stops working the moment it's ever used
# once (e.g. an open dev tab silently refreshing after the access token's 30-min TTL), and a
# subsequent fresh page load (cleared storage, new tab/device) does two dead round trips
# before bouncing to /login, which reads as "pages take forever to load" - that happened for
# real on 2026-08-15. When it does: don't debug it, just log in through the real UI (real
# username/password login exists now) instead of depending on this shortcut, or mint a fresh
# pair with a normal login call:
# curl -X POST <backend>/auth/login -H "Content-Type: application/json" \
# -d '{"username":"dev-test-user","password":"<the password>"}'
VITE_DEV_ACCESS_TOKEN=
VITE_DEV_REFRESH_TOKEN=
......@@ -10,8 +10,15 @@ export default defineConfig(({ mode }) => {
// proxy target below. It must never end up in the client bundle (unlike VITE_API_BASE_URL,
// which .env.development.local points at the proxy path instead of this directly - see the
// comment on the proxy block for why).
// Defaults to loopback, not the box's own public IP: vite and the backend run on the same
// host, so this proxy hop should never leave the machine. Pointing it at the public IP used
// to work only by accident, via Hetzner's NAT hairpinning a self-connection back in through
// the same firewall/routing path that already caused an earlier outage in this project -
// every single API call paid for a real (if usually fast) round trip through the cloud
// network for a call that's actually loopback-local. BACKEND_PROXY_TARGET still overrides
// this for the rare case the backend really does run elsewhere.
const env = loadEnv(mode, process.cwd(), '')
const backendProxyTarget = env.BACKEND_PROXY_TARGET || 'http://144.76.210.145:8000'
const backendProxyTarget = env.BACKEND_PROXY_TARGET || 'http://127.0.0.1:8000'
return {
// The Geolocation API (and other browser APIs) refuse to run at all on a plain http://
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment