Skip to content

Commit

Permalink
fixed Amplify 404 status
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhilsinclair committed Mar 5, 2025
1 parent dedf0d1 commit 7ee8872
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions cdk/lib/amplify-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
App,
BasicAuth,
GitHubSourceCodeProvider,
RedirectStatus,
} from "@aws-cdk/aws-amplify-alpha";
import * as cdk from "aws-cdk-lib";
import { BuildSpec } from "aws-cdk-lib/aws-codebuild";
Expand Down Expand Up @@ -40,10 +41,6 @@ export class AmplifyStack extends cdk.Stack {
cache:
paths:
- 'node_modules/**/*'
redirects:
- source: </^[^.]+$|.(?!(css|gif|ico|jpg|js|png|txt|svg|woff|woff2|ttf|map|json|webp)$)([^.]+$)/>
target: /
status: 404
`);

const username = cdk.aws_ssm.StringParameter.valueForStringParameter(
Expand Down Expand Up @@ -73,6 +70,12 @@ export class AmplifyStack extends cdk.Stack {
buildSpec: BuildSpec.fromObjectToYaml(amplifyYaml),
});

amplifyApp.addCustomRule({
source: "</^[^.]+$|.(?!(css|gif|ico|jpg|js|png|txt|svg|woff|woff2|ttf|map|json|webp)$)([^.]+$)/>",
target: "/",
status: RedirectStatus.NOT_FOUND_REWRITE,
});

amplifyApp.addBranch("main");
}
}

0 comments on commit 7ee8872

Please sign in to comment.