Skip to content

Commit

Permalink
feat(stacks.web): add blog redirect to web staging
Browse files Browse the repository at this point in the history
Signed-off-by: Braden Mars <bradenmars@bradenmars.me>
  • Loading branch information
BradenM committed Jul 3, 2024
1 parent d929160 commit fa009cc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/stacks/web/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ wave.addStageWithGitHubOptions(
{
domainName: 'staging.crisiscleanup.io',
fqdn: 'app.staging.crisiscleanup.io',
enableBlogRedirect: true,
},
{
env: config.$env!.staging!.cdkEnvironment,
Expand Down
15 changes: 15 additions & 0 deletions packages/stacks/web/src/web.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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
}

/**
Expand Down Expand Up @@ -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',
})
}
}
}

0 comments on commit fa009cc

Please sign in to comment.