-
Notifications
You must be signed in to change notification settings - Fork 46
Description
Type of issue
Missing information / new recipe needed
Description
When using AddViteApp with Aspire parameters (e.g., Google OAuth Client ID), there's no documented pattern for getting parameter values into the SPA at runtime.
The problem: Vite bakes VITE_* environment variables into the JavaScript bundle at build time. Aspire sets environment variables at runtime. This means .WithEnvironment("VITE_GOOGLE_CLIENT_ID", parameter) on a Vite resource doesn't work — the value isn't available when Vite compiles the frontend.
What we had to figure out ourselves:
- Pass the parameter to the API project as a regular env var:
.WithEnvironment("GOOGLE_CLIENT_ID", googleClientId) - Create a config endpoint in the API:
GET /api/config/google-client-id - Have the SPA fetch the config value at mount time instead of reading
import.meta.env
This is a universal problem for anyone using AddViteApp / AddNpmApp with parameters. A recipe or guide would save a lot of confusion.
Suggested docs location: The JavaScript hosting docs or the external parameters page would be natural homes.
Alternatively: A first-class API like AddViteApp(...).WithFrontendConfig("GOOGLE_CLIENT_ID", parameter) that auto-generates the config endpoint would be even better (that would be a dotnet/aspire feature request).
Page URL
https://learn.microsoft.com/en-us/dotnet/aspire/get-started/build-aspire-apps-with-nodejs
Content source URL
https://github.com/microsoft/aspire.dev/blob/main/docs/get-started/build-aspire-apps-with-nodejs.md