feat(dev): make Vite API proxy target configurable#103
Merged
Conversation
The dev server proxies `/api` to `http://localhost:8000` by default — the conventional standalone backend port. When the backend runs inside the local k3s dev stack from smartem-devtools, it is exposed on NodePort 30080 instead, leaving devs to either start a port-forward to keep the default working or hand-edit `vite.config.ts`. Read `VITE_API_PROXY_TARGET` via `loadEnv` so the proxy destination can be set from `.env.local` without touching the config or starting a port-forward. Default is unchanged, so anyone already on the port-forward workflow keeps working with no action. Applied to both `apps/smartem` and `apps/legacy` so the two dev servers stay in sync until legacy is retired.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The Vite dev server proxies
/apitohttp://localhost:8000by default — the conventional standalone backend port (uvicorndirectly, orkubectl port-forward svc/smartem-http-api-service 8000:80). When the backend runs inside the local k3s dev stack from smartem-devtools, it's exposed on NodePort 30080, which until now meant either starting a port-forward to keep the default working or hand-editingvite.config.ts.This PR reads
VITE_API_PROXY_TARGETvialoadEnvso the proxy destination can be set fromapps/smartem/.env.localwithout touching the config or starting a port-forward. The default is unchanged, so anyone already on the port-forward workflow keeps working with no action.apps/smartem/vite.config.tsandapps/legacy/vite.config.tsboth updated for parity until legacy is retired.apps/smartem/.env.exampledocuments the var alongsideVITE_ENABLE_MOCKS.Companion docs update on the smartem-devtools side: DiamondLightSource/smartem-devtools#218 grows a "Pointing the SmartEM frontend dev server at this stack" subsection in
docs/operations/kubernetes.md.Test plan
npm run typecheckclean across workspacesnpx biome checkclean on the twovite.config.tsfilesnpm run dev:smartemwith no env var set proxies tolocalhost:8000(existing behaviour)VITE_API_PROXY_TARGET=http://localhost:30080 npm run dev:smartemproxies to the k3s NodePort with no port-forward running