Commit d53c3623 authored by Aryan Noshirvnai's avatar Aryan Noshirvnai

Revert committing .env files - bake the correct default into code instead

Committing .env/.env.development/.env.production (previous commit) fixed
the immediate symptom (fresh checkout had no working config) but broke a
convention that exists for good reason: gitignoring .env means nobody has
to judge whether a given line is sensitive before adding it. "Nothing in
here is sensitive right now" is true but fragile - it only holds until
someone adds a real secret to that file later without remembering the
convention was bent for it.

The actual problem was "a missing env override silently breaks the app
with no error," not "the file isn't committed." Fixed properly: client.ts
now defaults VITE_API_BASE_URL to '/api' (the same-origin proxy path both
`vite dev` and `vite preview` already serve this app through) instead of
requiring an env file to supply it - matching the pattern vite.config.ts
already used for BACKEND_PROXY_TARGET. A fresh checkout now works
correctly with zero env files at all, verified by rebuilding with none
present and confirming '/api' is still what's baked into the bundle.

.env/.env.development/.env.production deleted and re-gitignored;
.env.example is back to being a pure template, documenting when you'd
actually need to override either default (a different deployment
topology), not real values to copy.
Co-Authored-By: 's avatarClaude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019i3NAUkLkHNbsPg5vKfzF9
parent 434f1a2e
Pipeline #1091 canceled with stage
# Base default for VITE_API_BASE_URL, all Vite modes. Both .env.development and .env.production
# (committed alongside this file - see the .gitignore comment) override this with the relative
# `/api` proxy path instead, since this box serves both dev and the "production" build through
# vite's own same-origin proxy rather than exposing the backend directly over https - see
# BACKEND_PROXY_TARGET below and stax_dev_mode_is_the_real_slowness in project memory. This
# absolute URL only actually takes effect if this app is ever built and served a different way
# (a real reverse proxy/CDN in front, backend on HTTPS) - don't delete it thinking it's dead,
# it's the fallback for that scenario.
VITE_API_BASE_URL=http://144.76.210.145:8000
# Loopback, not the public IP: vite and the backend run on the same host, so this hop should
# never leave the machine. Pointing it at the public IP used to "work" only by accident, via
# Hetzner NAT-hairpinning a self-connection back through the same firewall path that already
# caused an outage in this project once - every API call paid for a real cloud-network round
# trip for what's actually a loopback-local call. See vite.config.ts.
BACKEND_PROXY_TARGET=http://127.0.0.1:8000
# There used to be a VITE_DEV_ACCESS_TOKEN/VITE_DEV_REFRESH_TOKEN pair here for auto-login in
# dev mode - removed 2026-08-15. It was a single-use, rotating refresh token baked into this
# static file and shared across every consumer (every dev session, every test run, every
# curl); the instant any one of them used it, the backend rotated it and this file's copy went
# dead for everyone else, with no way to keep a static file in sync with a rotating secret.
# That's what "the site is slow/broken" turned out to be, repeatedly. Just log in for real
# instead - real username/password login is just as fast and has no such failure mode. (Local
# dev-only test account credentials live outside version control - do not put them in a
# committed file, this one included.)
# Committed (not gitignored - see the .gitignore comment for why): route API calls through
# the vite dev server's own same-origin proxy (see vite.config.ts) instead of hitting the
# backend directly, which the browser blocks as mixed content once the dev server itself is
# https://. This value is specific to `npm run dev` (Vite's "development" mode) - see
# .env.production for the equivalent override for `vite build`/`vite preview`, and plain .env
# for the base default plus BACKEND_PROXY_TARGET (not mode-specific).
VITE_API_BASE_URL=/api
# This is a reference template, not something you need to copy - .env, .env.development, and # Template only - copy to .env.local (gitignored, personal) if you actually need to override
# .env.production are all already committed in this repo with real, working values (see the # something. Nothing in this repo requires an env file to exist at all: api/client.ts defaults
# .gitignore comment: none of it has been a secret since the dev auto-login token pair was # VITE_API_BASE_URL to '/api' (the same-origin proxy path both `vite dev` and `vite preview`
# removed 2026-08-15). A fresh checkout works with zero setup. Use this file only if setting up # serve this app through - see stax_dev_mode_is_the_real_slowness in project memory for why
# a genuinely different deployment (a different box, a different proxy topology) where those # that matters), and vite.config.ts defaults BACKEND_PROXY_TARGET to http://127.0.0.1:8000.
# committed values don't apply - copy what you need into a new .env.local (gitignored, for a # A fresh checkout works correctly with zero setup.
# personal override) rather than editing the committed files for a one-off. #
# Only set VITE_API_BASE_URL if this build is ever served a genuinely different way - no vite
# Base URL of the stax_backend_api instance to talk to. Point this at the dev server while # process in front of it at all (e.g. dist/ served by nginx/Caddy directly, or the backend put
# developing, and at prod for a production build. # behind its own HTTPS-terminating reverse proxy/CDN) - in which case it needs the real,
# absolute backend URL instead of the proxy-relative default:
VITE_API_BASE_URL=http://144.76.210.145:8000 VITE_API_BASE_URL=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 # Only set BACKEND_PROXY_TARGET if vite's own proxy needs to reach a backend that isn't on
# still-http:// backend directly gets blocked as mixed content - route it through the dev # 127.0.0.1:8000 - e.g. the backend genuinely moved to a different host. Do NOT point this at
# server's own same-origin proxy instead. .env.development (committed) already does this: # this box's own public IP even if the backend is technically reachable there - that routes
# VITE_API_BASE_URL=/api # every API call through Hetzner's network via NAT hairpin instead of a loopback call, which
# Leave this file's VITE_API_BASE_URL above as the real absolute URL - it's the fallback for # already caused a real outage in this project once:
# any mode/deployment that doesn't override it. BACKEND_PROXY_TARGET=http://127.0.0.1:8000
#
# The exact same mixed-content problem hits a production build too, if `vite preview` is what's
# actually serving it on this same box (see stax_dev_mode_is_the_real_slowness in project
# memory - as of 2026-08-15 that's how this app is deployed: port 5173 runs `vite preview`
# against `dist/`, not a separate reverse-proxied host). `vite preview` reuses vite.config.ts's
# proxy, but env resolution happens at BUILD time (`vite build`, mode=production), not at
# preview/serve time - .env.production (committed) supplies the same /api override for that
# case. If this app is ever deployed differently (a real reverse proxy/CDN in front, backend on
# HTTPS), delete or repoint .env.production rather than leaving a stale override in place.
#
# Either way: the env value is baked in at build time, not read fresh by an already-running
# preview server - `npm run build` again and restart `vite preview` after touching either
# override file, or the old build keeps serving with the old value.
# There is no dev-only auto-login token pair anymore (removed 2026-08-15) - it was a # There is no dev-only auto-login token pair anymore (removed 2026-08-15) - it was a
# single-use, rotating refresh token baked into a static file and shared across every # single-use, rotating refresh token baked into a static file and shared across every
......
# Committed (not gitignored - see the .gitignore comment for why): route API calls through
# vite preview's own same-origin proxy (see vite.config.ts's server.proxy, which vite preview
# reuses) instead of the absolute http:// URL in plain .env - the browser blocks that as mixed
# content once the page itself is https://, exactly like in dev mode. This override exists
# because `vite preview` (serving this box's own build, through its own proxy) is how the
# production build actually gets served here - see stax_dev_mode_is_the_real_slowness in
# project memory. A real deployment behind its own reverse proxy/CDN with the backend on HTTPS
# wouldn't need this override; if this project ever moves to that, delete this file rather
# than leave a stale value here silently overriding the real one in .env.
VITE_API_BASE_URL=/api
...@@ -10,13 +10,8 @@ lerna-debug.log* ...@@ -10,13 +10,8 @@ lerna-debug.log*
node_modules node_modules
dist dist
dist-ssr dist-ssr
# Personal per-developer overrides only (e.g. .env.local) - genuine deployment config
# (.env, .env.development, .env.production) is committed on purpose, see .env.example's
# comment. None of it has held a secret since the dev auto-login token pair was removed
# 2026-08-15 - a URL and a proxy target aren't sensitive, and a fresh checkout silently
# missing them caused real, hard-to-diagnose outages (mixed-content blocked API calls with no
# server-side error) more than once that same day.
*.local *.local
.env
.cache .cache
# Editor directories and files # Editor directories and files
......
const API_BASE_URL = import.meta.env.VITE_API_BASE_URL as string // Defaults to the same-origin proxy path, not an absolute URL: both `vite dev` and
// `vite preview` (how this app is actually served, in every mode currently in use - see
// stax_dev_mode_is_the_real_slowness in project memory) proxy /api to the backend themselves,
// so this works correctly with zero env config at all. VITE_API_BASE_URL only needs to be set
// (in a gitignored .env.local, never committed - see .env.example) for a deployment that
// serves the built dist/ some other way, with no such proxy in front of it.
const API_BASE_URL = (import.meta.env.VITE_API_BASE_URL as string | undefined) || '/api'
const ACCESS_TOKEN_KEY = 'stax_access_token' const ACCESS_TOKEN_KEY = 'stax_access_token'
const REFRESH_TOKEN_KEY = 'stax_refresh_token' const REFRESH_TOKEN_KEY = 'stax_refresh_token'
......
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