feat: add SPA route rewrite CloudFront Function to StaticSiteConstruct#65
Merged
ncipollina merged 5 commits intomainfrom Apr 6, 2026
Merged
feat: add SPA route rewrite CloudFront Function to StaticSiteConstruct#65ncipollina merged 5 commits intomainfrom
ncipollina merged 5 commits intomainfrom
Conversation
Attaches a CloudFront Function (viewer request) to the default S3 behavior that rewrites requests with no file extension to /index.html. This enables client-side routing for Blazor WASM and other SPAs without affecting API 404s, which are served via the /api/* behavior (a separate origin) and never reach the default behavior. Previously, missing SPA routes returned a CloudFront-level 404 because the S3 website endpoint serves its error document with a 404 status, and adding a distribution-level 404 → /index.html error response would also swallow legitimate API not-found responses. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…Construct Callers can now supply an optional IFunction via PostConfirmationTrigger on ICognitoUserPoolConstructProps; when provided it is wired to the UserPool via AddTrigger(UserPoolOperation.POST_CONFIRMATION, ...). Also bumps Amazon.CDK.Lib from 2.246.0 to 2.248.0. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds CloudFront viewer-request rewriting to support SPA client-side routing in StaticSiteConstruct, plus an optional Cognito User Pool post-confirmation trigger hook, and bumps package/library versions.
Changes:
- Add a CloudFront Function to rewrite extensionless paths to
/index.htmlon the default behavior (SPA routing fix). - Add optional
PostConfirmationTriggersupport toCognitoUserPoolConstruct. - Bump
Amazon.CDK.Liband the libraryVersionPrefix.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/LayeredCraft.Cdk.Constructs/StaticSiteConstruct.cs | Introduces a CloudFront Function and associates it with the default behavior to enable SPA route rewrites. |
| src/LayeredCraft.Cdk.Constructs/Models/CognitoUserPoolConstructProps.cs | Extends Cognito props with an optional post-confirmation Lambda trigger property. |
| src/LayeredCraft.Cdk.Constructs/CognitoUserPoolConstruct.cs | Wires the optional post-confirmation trigger into the created Cognito User Pool. |
| Directory.Packages.props | Updates Amazon.CDK.Lib dependency version. |
| Directory.Build.props | Bumps package version prefix. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…on trigger Adds a cognito-idp:AdminAddUserToGroup policy statement to the trigger function's execution role when a PostConfirmationTrigger is provided, resolving the circular dependency caused by referencing the UserPool ARN in the role policy. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a CloudFront Function (viewer request event) to the default S3 behavior in
StaticSiteConstructthat rewrites requests with no file extension to/index.html. This enables correct client-side routing for Blazor WASM and other SPAs — specifically fixing cases where routes like/profileor/authentication/login-callbackreturned 404 instead of loading the app.The previous workaround (distribution-level
404 → /index.htmlerror response) couldn't be used because it would also swallow legitimate API 404 responses. The CloudFront Function approach is safe because API requests match the/api/*behavior (a separate Lambda origin) and never reach the default behavior where this function runs.Changes
StaticSiteConstruct.cs— creates aCloudFront.Functionwith a JS_2_0 viewer request handler and attaches it toDefaultBehavior.FunctionAssociationsRewrite logic:
Validation
dotnet buildpasses with 0 warnings across net8.0 / net9.0 / net10.0 targets.js,.wasm,.css,.json,.br,.gz,.ico,.png,.svg/profile,/authentication/login-callback,/) correctly rewrite to/index.html/api/*) use a separate CloudFront behavior and are never affectedNotes for Reviewers
The existing
403 → /index.htmldistribution-level error response is retained as a safety net for any S3 access-denied scenarios. The CloudFront Function handles the primary SPA routing case at the request level before S3 is ever reached.This change applies to all consumers of
StaticSiteConstruct— any static site using this construct is a SPA and benefits from this behavior unconditionally.