From 12db36e6686a798a6bf6ef4c63e5e034bd4ffe00 Mon Sep 17 00:00:00 2001 From: Braden Mars Date: Wed, 3 Jul 2024 20:19:38 -0500 Subject: [PATCH] fix(stacks.web): use separate origin for blog redirect + specify behavior path, fix regex pattern Signed-off-by: Braden Mars --- packages/stacks/web/src/web.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/stacks/web/src/web.ts b/packages/stacks/web/src/web.ts index b050aaa..2a77df6 100644 --- a/packages/stacks/web/src/web.ts +++ b/packages/stacks/web/src/web.ts @@ -3,6 +3,7 @@ import { CloudFrontUrlRewrite } from '@crisiscleanup/construct.awscdk.cloudfront 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' +import * as origins from 'aws-cdk-lib/aws-cloudfront-origins' import * as route53 from 'aws-cdk-lib/aws-route53' import * as route53Targets from 'aws-cdk-lib/aws-route53-targets' import type { Construct } from 'constructs' @@ -114,12 +115,15 @@ export class CrisisCleanupWeb extends Stack { } if (props.enableBlogRedirect) { + const blogOrigin = new origins.HttpOrigin('blog.' + props.domainName) new CloudFrontUrlRewrite(this, id + '-BlogRedirect', { distribution: this.website.cloudFrontDistribution, fromHostname: `blog.${props.domainName}`, toHostname: props.fqdn, - redirectUriPattern: '^/d{4}/d{2}/(.*).html', + redirectUriPattern: '^/\\\\d{4}/\\\\d{2}/(.*)\\\\.html$', targetUriPattern: '/blog/post/$1', + behaviorPath: '/*/*/*.html', + origin: blogOrigin, }) if (this.zone) { new route53.ARecord(this, id + '-alias-record-blog', {