From fa009ccc413534a5360d290b5cf7e0738c26c733 Mon Sep 17 00:00:00 2001 From: Braden Mars Date: Wed, 3 Jul 2024 17:50:23 -0500 Subject: [PATCH] feat(stacks.web): add blog redirect to web staging Signed-off-by: Braden Mars --- packages/stacks/web/src/main.ts | 1 + packages/stacks/web/src/web.ts | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/packages/stacks/web/src/main.ts b/packages/stacks/web/src/main.ts index 32c5ef77..bde1a382 100644 --- a/packages/stacks/web/src/main.ts +++ b/packages/stacks/web/src/main.ts @@ -165,6 +165,7 @@ wave.addStageWithGitHubOptions( { domainName: 'staging.crisiscleanup.io', fqdn: 'app.staging.crisiscleanup.io', + enableBlogRedirect: true, }, { env: config.$env!.staging!.cdkEnvironment, diff --git a/packages/stacks/web/src/web.ts b/packages/stacks/web/src/web.ts index ffe40791..f58f5e5c 100644 --- a/packages/stacks/web/src/web.ts +++ b/packages/stacks/web/src/web.ts @@ -1,4 +1,5 @@ import { StaticWebsite, StaticWebsiteOrigin } from '@aws/pdk/static-website' +import { CloudFrontUrlRewrite } from '@crisiscleanup/construct.awscdk.cloudfront-url-rewrite' import { Duration, Stack, type StackProps } from 'aws-cdk-lib' import * as acm from 'aws-cdk-lib/aws-certificatemanager' import * as cloudfront from 'aws-cdk-lib/aws-cloudfront' @@ -27,6 +28,10 @@ export interface CrisisCleanupWebProps { * Utilize PRICE_CLASS_ALL for CloudFront distribution. */ readonly globalPriceClass?: boolean + /** + * Enable blog.crisiscleanup -> crisiscleanup/blog redirect. + */ + readonly enableBlogRedirect?: boolean } /** @@ -104,5 +109,15 @@ export class CrisisCleanupWeb extends Stack { recordName: props.fqdn, }) } + + if (props.enableBlogRedirect) { + new CloudFrontUrlRewrite(this, id + '-BlogRedirect', { + distribution: this.website.cloudFrontDistribution, + fromHostname: `blog.${props.domainName}`, + toHostname: props.fqdn, + redirectUriPattern: '^/d{4}/d{2}/(.*).html', + targetUriPattern: '/blog/post/$1', + }) + } } }