Skip to content

Docs: TypeScript AppHost DOES expose withEndpointsInEnvironment (project-resources page says it does not) #1464

Description

Page

integrations/dotnet/project-resources → "Filter endpoints in environment variables"

Source: project-resources.mdx

Problem

The TypeScript tab of the "Filter endpoints in environment variables" section states:

"The TypeScript AppHost doesn't currently expose WithEndpointsInEnvironment. To exclude an endpoint from environment variable injection, define only the endpoints you need and omit the admin endpoint from the project resource."

But the TypeScript AppHost does expose it. There is a dedicated ATS-friendly overload marked [AspireExport]src/Aspire.Hosting/Ats/CoreExports.cs:

[AspireExport]
public static IResourceBuilder<ProjectResource> WithEndpointsInEnvironment(
    this IResourceBuilder<ProjectResource> resource,
    string[] endpointNames)

The predicate overload WithEndpointsInEnvironment(Func<EndpointAnnotation, bool> filter) is [AspireExportIgnore] because Func<> isn't ATS-compatible, and its comment explicitly points to the array-based export as "the ATS-friendly implementation."

It appears in the generated TypeScript surface — src/Aspire.Hosting/api/Aspire.Hosting.ats.txt:

Aspire.Hosting/withEndpointsInEnvironment(endpointNames: string[]) -> Aspire.Hosting/Aspire.Hosting.ApplicationModel.ProjectResource

and the repository's own polyglot TypeScript AppHost uses it — tests/PolyglotAppHosts/Aspire.Hosting/TypeScript/apphost.mts:

await project.withEndpointsInEnvironment(["https"]);

Note on semantics

The exported TypeScript overload takes an allow-list of endpoint names to include (string[]), which is the inverse of the C# predicate example on the page (which excludes endpoints by returning false). So the correct TypeScript guidance to keep admin out of the environment is to list the endpoints you want to keep:

await builder.addProject("apiservice", "../Networking.ApiService/Networking.ApiService.csproj")
    .withHttpsEndpoint()
    .withHttpsEndpoint({ port: 19227, name: "admin" })
    .withEndpointsInEnvironment(["https"]); // include only "https"; "admin" is excluded

Suggested fix

Replace the "doesn't currently expose WithEndpointsInEnvironment" note in the TypeScript tab with the withEndpointsInEnvironment(endpointNames) allow-list form and an example, noting the include-vs-exclude semantic difference from the C# predicate overload.

Provenance

aspire.dev release/13.5 (project-resources.mdx); aspire release/13.5 (CoreExports.cs, Aspire.Hosting.ats.txt, PolyglotAppHosts TypeScript AppHost). Confirmed working live against the 13.5 candidate CLI 13.5.0-pr.17553.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions