Skip to content

Conversation

mishraomp
Copy link
Collaborator

No description provided.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds SPA routing support to the CloudFront distribution by mapping 403 errors to a fallback path when using S3 origins.

  • Introduces a dynamic custom_error_response block to map 403 responses to the root path for distribution_type = "s3".

content {
error_code = 403
response_code = 200
response_page_path = "/"
Copy link
Preview

Copilot AI Jun 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The response_page_path should point to your SPA entry file (e.g., /index.html) instead of just / to ensure CloudFront serves the correct object.

Suggested change
response_page_path = "/"
response_page_path = "/index.html"

Copilot uses AI. Check for mistakes.

dynamic "custom_error_response" {
for_each = var.distribution_type == "s3" ? [1] : []
content {
error_code = 403
Copy link
Preview

Copilot AI Jun 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider also handling 404 errors by adding a second custom_error_response block mapping 404 to 200, which is a common practice for SPAs to catch missing routes.

Copilot uses AI. Check for mistakes.

@mishraomp mishraomp merged commit 06ac925 into main Jun 28, 2025
23 checks passed
@mishraomp mishraomp deleted the fix/spa-routing branch June 28, 2025 22:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant