Skip to content

feat(dev): make Vite API proxy target configurable#103

Merged
vredchenko merged 1 commit into
mainfrom
feat/configurable-api-proxy-target
May 29, 2026
Merged

feat(dev): make Vite API proxy target configurable#103
vredchenko merged 1 commit into
mainfrom
feat/configurable-api-proxy-target

Conversation

@vredchenko
Copy link
Copy Markdown
Collaborator

Summary

The Vite dev server proxies /api to http://localhost:8000 by default — the conventional standalone backend port (uvicorn directly, or kubectl 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-editing vite.config.ts.

This PR reads VITE_API_PROXY_TARGET via loadEnv so the proxy destination can be set from apps/smartem/.env.local without 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.ts and apps/legacy/vite.config.ts both updated for parity until legacy is retired.
  • apps/smartem/.env.example documents the var alongside VITE_ENABLE_MOCKS.
  • Root README prerequisites note mentions the override and links to the smartem-devtools k8s ops page.

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 typecheck clean across workspaces
  • npx biome check clean on the two vite.config.ts files
  • Default path: npm run dev:smartem with no env var set proxies to localhost:8000 (existing behaviour)
  • Override: VITE_API_PROXY_TARGET=http://localhost:30080 npm run dev:smartem proxies to the k3s NodePort with no port-forward running

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.
@vredchenko vredchenko merged commit 5c66f87 into main May 29, 2026
10 checks passed
@vredchenko vredchenko deleted the feat/configurable-api-proxy-target branch May 29, 2026 18:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant