Repository navigation
Support SPA fallback for static website publishing - #21871
Shayne Boyer (spboyer) wants to merge 4 commits into
Conversation
Co-authored-by: Copilot App <[email protected]>
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 21871Or
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 21871" |
Co-authored-by: Copilot App <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
The SPA fallback fails restricted host filtering for valid deep links and can collide with later configuration, causing unintended load balancing between backend and loopback destinations.
2 open issues
What changed in this PR
Adds SPA deep-link support to JavaScript static-site publishing, addressing #17675 while keeping generic YARP fallback opt-in.
Changes:
- Adds a shared loopback fallback for extensionless GET and HEAD requests, with an explicit opt-out.
- Documents route precedence and exposes fallback configuration to C# and TypeScript AppHosts.
- Expands unit, container, and deployment verification for navigation, missing assets, API routing, and disabled fallback.
| File | Description |
|---|---|
tests/PolyglotAppHosts/Aspire.Hosting.Yarp/TypeScript/apphost.mts |
Exercises TypeScript fallback configuration. |
tests/PolyglotAppHosts/Aspire.Hosting.JavaScript/TypeScript/apphost.mts |
Exercises the static-site fallback opt-out. |
tests/Aspire.Hosting.Yarp.Tests/YarpFunctionalTests.cs |
Tests routing behavior and native-fallback coexistence. |
tests/Aspire.Hosting.Yarp.Tests/AddYarpTests.cs |
Tests generated configuration, ordering, and name collisions. |
tests/Aspire.Hosting.JavaScript.Tests/Snapshots/AddJavaScriptAppTests.VerifyDockerfileWhenPublishedAsStaticWebsiteWithDefaultOptions.verified.txt |
Adds the renamed default-options Dockerfile snapshot. |
tests/Aspire.Hosting.JavaScript.Tests/AddViteAppTests.cs |
Covers fallback defaults, opt-out, and endpoint configuration. |
tests/Aspire.Hosting.JavaScript.Tests/AddJavaScriptAppTests.cs |
Renames the default publishing test. |
tests/Aspire.Cli.EndToEnd.Tests/JavaScriptPublishTests.cs |
Expands deployment scenarios and scopes cleanup. |
tests/Aspire.Cli.EndToEnd.Tests/Fixtures/JsPublish/verify.sh |
Verifies deployed fallback responses and captures diagnostics. |
tests/Aspire.Cli.EndToEnd.Tests/Fixtures/JsPublish/api/server.js |
Returns 404 for unknown API routes. |
src/Aspire.Hosting.Yarp/YarpStaticFileFallback.cs |
Generates shared loopback fallback configuration. |
src/Aspire.Hosting.Yarp/YarpResourceExtensions.cs |
Adds WithSpaFallback and static-file integration. |
src/Aspire.Hosting.Yarp/README.md |
Documents fallback usage and precedence. |
src/Aspire.Hosting.JavaScript/README.md |
Documents default fallback behavior and opt-out. |
src/Aspire.Hosting.JavaScript/PublishAsStaticWebsiteOptions.cs |
Adds EnableSpaFallback, enabled by default. |
src/Aspire.Hosting.JavaScript/JavaScriptHostingExtensions.cs |
Connects publishing options to fallback generation. |
src/Aspire.Hosting.JavaScript/Aspire.Hosting.JavaScript.csproj |
Links the shared YARP fallback implementation. |
Review effort: Balanced
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
🔵 Needs a closer look
The loopback route replaces the original Host header, causing SPA deep links to return HTTP 400 under restrictive AllowedHosts settings; it needs host preservation and regression coverage.
2 open issues
Review effort: Balanced
Co-authored-by: Copilot App <[email protected]>
There was a problem hiding this comment.
🔵 Needs a closer look
The anonymous loopback fallback changes routing precedence and authorization boundaries, while API/security sign-off and full CLI deployment validation remain outstanding.
No open issues 🎉
2 resolved since last review
Review effort: Balanced
This comment has been minimized.
This comment has been minimized.
|
Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt. |
…2164) ## Description Graduate Next.js hosting and the existing JavaScript publishing APIs from `ASPIREJAVASCRIPT001`, so consumers no longer need experimental-warning suppressions for these scenarios. Retain all APIs, signatures, generated artifacts, runtime behavior, and the existing **release/17.0** build-validation behavior. - Remove the markers from `AddNextJsApp`, `NextJsAppResource`, `DisableBuildValidation`, both `PublishAsStaticWebsite` overloads and their internal adapter/core, `PublishAsStaticWebsiteOptions`, `PublishAsNodeServer`, and `PublishAsPackageScript`. - Remove now-unnecessary suppressions from existing consumer tests and playgrounds. Those tests now compile and exercise the APIs without suppressing this diagnostic. - Document the stable publishing shapes and existing Next.js prerequisites in the integration README. Generated `api/*.cs` baselines remain untouched. - This PR does not graduate Deno or future APIs that might reuse `ASPIREJAVASCRIPT001`. Deno was independently graduated on the release target; the merge preserves that change. Fixes # (issue) ### User-facing usage Existing calls remain unchanged; C# callers can remove their `ASPIREJAVASCRIPT001` suppressions: ```csharp builder.AddNextJsApp("frontend", "../frontend"); builder.AddViteApp("static-site", "../static-site") .PublishAsStaticWebsite(); ``` The existing exported TypeScript API names remain unchanged: ```typescript await builder.addNextJsApp("frontend", "../frontend"); await builder.addViteApp("static-site", "../static-site") .publishAsStaticWebsite(); ``` ### Publishing contract evaluation This PR proposes graduation of the current contracts, not a new framework-wide support guarantee or a claim of prior maintainer approval: | Shape | Contract retained | |---|---| | Static website | Build the configured output directory (`dist` by default), copy it to YARP's static-file root, and preserve optional API proxying, prefix stripping, and endpoint selection. Unmatched-path behavior is unchanged. | | Node server | Copy the selected built output and run the specified entry point directly with Node.js. | | Package script | Run the selected script with the configured package manager and its runtime dependencies; preserve the distinct Node/Bun/Deno image-generation paths. | | Next.js | Preserve standalone output: `public/`, `.next/standalone/`, and `.next/static/`, with `node server.js` in the runtime image. A `public/` directory remains required. | Next.js configuration inspection remains a static heuristic, not execution of `next.config.*`. `DisableBuildValidation()` still supports dynamically supplied configuration without changing the required output. Existing user Dockerfiles and explicit entrypoint overrides retain their current treatment. **Release-specific boundary:** release/17.0 has the older resource-annotation validation pipeline, not main's container `AddPublishValidation` integration. This PR does not port that integration or its Azure graph tests, and does not claim release verification of validation-before-image-build behavior across Azure Container Apps/App Service or excluded-resource handling. The README omits those main-specific guarantees. Validation behavior on the release branch is unchanged by this PR. The workspace proposal #16839 and SPA-fallback proposal #21871 are not duplicate graduation PRs and are not included here. In particular, this PR does not approve their new APIs or change the current static-site fallback default. Any later change to these now-stable contracts still needs its own compatibility review. ### Release branch repair Replayed only the original stabilization commit `c1b09a678919c92a682ce7bf48dd8d299bf0abd0`, using its verified original-main fork point `793dfe6e254fe050af24cb7bcfba214066dcaab8`, onto release/17.0 at `9a97ab889bfb731de74ead0280be279ffdd000bf`. No release-to-head history range was cherry-picked. The sole conflict was a suppression removal in `JavaScriptPublishValidationTests.cs`, a test file absent from release. Kept it absent instead of importing main features/tests. A second documentation-only commit removes unsupported release validation guarantees. The replay initially contained **2 scoped commits and 11 files**, rather than unrelated main history. On November 15, merged the release target at `a509f094e0ee87d17dc0e1cc9bca84f7ca2623da` to resolve reported conflicts. Kept both the Next.js/publishing documentation and the target's independently graduated Deno documentation; removed both obsolete suppressions from the conflicted Deno test file. The target-relative diff remains 11 scoped files. No history rewrite or additional API/runtime behavior changes. ### Introduction attribution @davidfowl introduced the Next.js resource, validation opt-out, static-website options/helpers, Node-server helper, and original package-script helper in #15736 ([introducing commit](96a3327)). The package-script helper was subsequently renamed from `PublishAsNpmScript` to `PublishAsPackageScript` in #17382 ([rename commit](5384db2)), also by @davidfowl. Attribution was checked against introducing code history and the GitHub commit/PR author identities, not the merge committer or latest editor. No attribution uncertainty identified; these are mentions, not reviewer assignments. ### Validation **Current release/17.0-based branch:** - **Passed again after the November 15 conflict resolution, 338 tests, 0 failed, 0 skipped**, including the project build, with the exact focused command below. **Passed:** `git diff --cached --check origin/release/17.0` before committing the merge. The earlier CI `Final Results` failure was an aggregate dependent-job failure also reported on the target by the native PR finisher; it is not worked around in this PR. - **Passed, 338 tests, 0 failed, 0 skipped:** existing consumer/API tests, generated artifact snapshots, and release's existing Next.js validation cases. The negative pipeline test also emitted expected failures from building its deliberately invalid npm fixture; the test run exited 0. ```bash dotnet test --project tests/Aspire.Hosting.JavaScript.Tests/Aspire.Hosting.JavaScript.Tests.csproj --no-launch-profile -- --filter-class '*.AddJavaScriptAppTests' --filter-class '*.AddViteAppTests' --filter-class '*.NodeJsPublicApiTests' --filter-class '*.AddNodeAppTests' --filter-class '*.AddDenoAppTests' --filter-not-trait 'quarantined=true' --filter-not-trait 'outerloop=true' ``` - **Passed:** `git diff --check origin/release/17.0...HEAD`. No generated snapshot or API baseline changes. - **Not run on release:** main-only `JavaScriptPublishValidationTests` (absent), successful live framework image builds, CLI multi-framework deployment E2E, live Azure deployment, or a full repository suite. The passing release tests do not establish end-to-end deployment success for every framework or main's stronger validation-graph guarantees. **Historical main-based validation only; not release validation:** - **Passed, 114 baseline tests before changes:** ```bash dotnet test --project tests/Aspire.Hosting.JavaScript.Tests/Aspire.Hosting.JavaScript.Tests.csproj --no-launch-profile -- --filter-class '*.AddJavaScriptAppTests' --filter-class '*.AddViteAppTests' --filter-class '*.NodeJsPublicApiTests' --filter-not-trait 'quarantined=true' --filter-not-trait 'outerloop=true' ``` - **Passed, 344 tests after changes on main:** ```bash dotnet test --project tests/Aspire.Hosting.JavaScript.Tests/Aspire.Hosting.JavaScript.Tests.csproj --no-launch-profile -- --filter-class '*.AddJavaScriptAppTests' --filter-class '*.AddViteAppTests' --filter-class '*.NodeJsPublicApiTests' --filter-class '*.AddNodeAppTests' --filter-class '*.AddDenoAppTests' --filter-not-trait 'quarantined=true' --filter-not-trait 'outerloop=true' ``` - **Passed, 2 Azure validation-graph tests on main:** ```bash dotnet test --project tests/Aspire.Hosting.Azure.Tests/Aspire.Hosting.Azure.Tests.csproj --no-launch-profile -- --filter-class '*.JavaScriptPublishValidationTests' --filter-not-trait 'quarantined=true' --filter-not-trait 'outerloop=true' ``` ## Checklist - Is this feature complete? - [x] Yes. Ready to ship. - [ ] No. Follow-up changes expected. - Are you including unit tests for the changes and scenario tests if relevant? - [x] Yes - [ ] No - Did you add public API? - [ ] Yes - If yes, did you have an API Review for it? - [ ] Yes - [ ] No - Did you add `<remarks />` and `<code />` elements on your triple slash comments? - [ ] Yes - [ ] No - [x] No - Does the change make any security assumptions or guarantees? - [ ] Yes - If yes, have you done a threat model and had a security review? - [ ] Yes - [ ] No - [x] No --------- Co-authored-by: Maddy Montaquila <[email protected]> Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
Tests selector54 / 101 PR test projects · 4 PR jobs, from 22 changed files. Selected PR test projects (54 / 101)
Selected PR jobs (4)
How these were chosen — grouped by what changed
🔧 show 39
🔧 🧪 📦 affected project 🔧 📦 affected project 🔧 🔧 🔧 🔧 🧪 🧪 🧪 🧪 🧪 🧪 🧪 🧪 🧪 🧪 🧪 Job reasons
Selection computed for commit |
|
Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt. |

Description
Fixes #17675
JavaScript apps published with
PublishAsStaticWebsitenow serveindex.htmlfor unmatched GET and HEAD navigation paths, so Angular and other SPAs work when a deep link is opened or refreshed. Missing assets still return 404, and API routes with a lower order continue to take precedence. Existing generic YARP static-file behavior is unchanged unless its new fallback API is explicitly enabled.The currently published YARP image does not yet include the native SPA fallback introduced upstream in dotnet/yarp#3006. Until it does, Aspire configures a maximum-order reverse-proxy route to the existing HTTP listener on loopback. A same-order catch-all can take precedence differently, so the fallback can be disabled or a lower-order route used.
User-facing usage
Static website publishing enables the fallback by default. A non-SPA site can preserve 404 responses for unmatched paths:
Breaking changes
Previously, unmatched extensionless paths on a published JavaScript static site returned 404; they now serve
index.html. Sites that require the old behavior can setEnableSpaFallback/enableSpaFallbacktofalse.Security considerations
The fallback introduces a proxy route to
index.htmlon the existing loopback HTTP listener; it does not open a new listener. It does not inherit authorization policies from other YARP routes. A catch-all with the same maximum order can be overridden by the fallback, so deployments that rely on that route for access control should use a lower order or disable the fallback.Validation
MSBUILDTERMINALLOGGER=false dotnet test --project tests/Aspire.Hosting.Yarp.Tests/Aspire.Hosting.Yarp.Tests.csproj --no-launch-profile -- --filter-class '*.AddYarpTests' --filter-class '*.YarpFunctionalTests' --filter-not-trait 'quarantined=true' --filter-not-trait 'outerloop=true'. This includes real-container routing and native-fallback coexistence coverage.MSBUILDTERMINALLOGGER=false dotnet test --project tests/Aspire.Hosting.Yarp.Tests/Aspire.Hosting.Yarp.Tests.csproj --no-launch-profile -- --filter-method '*.StaticFilesServeSpaFallbackWithExpectedProxyRoutePriority' --filter-not-trait 'quarantined=true' --filter-not-trait 'outerloop=true', rerun after the final container-test assertion.MSBUILDTERMINALLOGGER=false dotnet test --project tests/Aspire.Hosting.JavaScript.Tests/Aspire.Hosting.JavaScript.Tests.csproj --no-launch-profile -- --filter-class '*.AddViteAppTests' --filter-class '*.AddJavaScriptAppTests' --filter-not-trait 'quarantined=true' --filter-not-trait 'outerloop=true'../node_modules/.bin/tsc --noEmit --target es2022 --module nodenext --moduleResolution nodenext --skipLibCheck --strict javascript.mts yarp.mtsagainst both checked-in TypeScript fixtures and the generated SDK in a temporary workspace.bash -n tests/Aspire.Cli.EndToEnd.Tests/Fixtures/JsPublish/verify.shandnode --check tests/Aspire.Cli.EndToEnd.Tests/Fixtures/JsPublish/api/server.js; a containerized stub harness also exercised deployment verification success and missing-port diagnostics.AllPublishMethodsBuildDockerImagesdeployment scenario. A source-built Linux CLI archive was unavailable and direct npm registry access failed in this environment. This draft is awaiting that end-to-end validation and API/security review.Checklist
<remarks />and<code />elements on your triple slash comments?