From 3dc7dedec4d3cd649a7f541921bd5fa41bf838c3 Mon Sep 17 00:00:00 2001 From: Riley Chase <1491530+Nadock@users.noreply.github.com> Date: Wed, 31 Jul 2024 21:52:45 +0930 Subject: [PATCH] feat: Add support for our new domain names (#344) * Add `taylorchase.net` SAN for website ACM cert * Add `taylorchase.net` additional CF alias * Redirect users back to primary domain * Add additional SAN for `rileychase.au` and `taylorchase.au` * Add distribution aliases for `rileychase.au` and `taylorchase.au` --- aws/acm_cert_cfn.yml | 4 ++++ aws/website_cfn.yml | 26 ++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/aws/acm_cert_cfn.yml b/aws/acm_cert_cfn.yml index 5125fb65..3aeb9052 100644 --- a/aws/acm_cert_cfn.yml +++ b/aws/acm_cert_cfn.yml @@ -28,6 +28,10 @@ Resources: Value: rileychase.net - Key: STAGE Value: production + SubjectAlternativeNames: + - rileychase.au + - taylorchase.au + - taylorchase.net Outputs: diff --git a/aws/website_cfn.yml b/aws/website_cfn.yml index 8e0747ec..fb5e6d95 100644 --- a/aws/website_cfn.yml +++ b/aws/website_cfn.yml @@ -80,6 +80,11 @@ Resources: DistributionConfig: Aliases: - !Ref DomainName + # This is not portable, if you're copying this you'll want to remove the + # additional domains below. + - rileychase.au + - taylorchase.net + - taylorchase.au Comment: !Ref AWS::StackName CustomErrorResponses: - ErrorCode: 400 @@ -191,6 +196,23 @@ Resources: FunctionCode: | function handler(event) { var request = event.request; + + // Redirect users on alternate domains back to the primary domain. + var host = event.request.headers.host.value; + if (host !== 'rileychase.net') { + var location = 'https://rileychase.net' + if (!request.uri.startsWith('/')) { + location += '/' + } + location += request.uri + + return { + statusCode: 302, + statusDescription: 'Found', + headers: { 'location': { value: location } } + } + } + var uri = request.uri; var leaf = uri.split("/")[uri.split("/").length - 1]; @@ -216,14 +238,14 @@ Resources: AliasTarget: DNSName: !GetAtt WebsiteDistribution.DomainName EvaluateTargetHealth: false - # The following HosteZoneId is always used for alias records pointing to CF. + # The following HosteZoneId is always used for alias records pointing to CF. HostedZoneId: Z2FDTNDATAQYW2 - Name: !Ref DomainName Type: AAAA AliasTarget: DNSName: !GetAtt WebsiteDistribution.DomainName EvaluateTargetHealth: false - # The following HosteZoneId is always used for alias records pointing to CF. + # The following HosteZoneId is always used for alias records pointing to CF. HostedZoneId: Z2FDTNDATAQYW2