Skip to content

Feature request: WithFrontendConfig API for passing Aspire parameters to SPA frontends #14471

@maddymontaquila

Description

@maddymontaquila

Is your feature request related to a problem?

Aspire parameters (from AddParameter) are set at runtime, but Vite/React/Angular bake environment variables at build time. There is no built-in way to pass an Aspire parameter to a SPA frontend.

The current workaround requires:

  1. Passing the parameter to the API as an env var (WithEnvironment)
  2. Writing a custom /api/config/{key} endpoint in the API project
  3. Having the SPA fetch from that endpoint at mount time

Every team using AddViteApp / AddNpmApp with parameters will need this pattern. We filed a docs recipe request at microsoft/aspire.dev#394 but believe this should also be a first-class product feature.

Describe the solution you'd like

A WithFrontendConfig API (or similar) that bridges Aspire parameters to SPA frontends:

builder.AddViteApp("frontend", "./src/frontend")
    .WithFrontendConfig("GOOGLE_CLIENT_ID", googleClientId);

This could auto-generate a config endpoint (or inject a __config.json at a well-known path like /__aspire/config) that the SPA can fetch at runtime.

Describe alternatives you've considered

Additional context

We're using Aspire 13.2.0-preview.1 with AddViteApp + WithPnpm() and a React 19 frontend. The workaround (config endpoint pattern) has been stable across two sprints and works well — but it's boilerplate that every SPA+Aspire project will reinvent.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-app-modelIssues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions