diff --git a/terraform/shortdns.js b/terraform/shortdns.js index 532035a..2df0f2d 100644 --- a/terraform/shortdns.js +++ b/terraform/shortdns.js @@ -1,12 +1,16 @@ -exports.handler = async () => { +exports.handler = async (event) => { + const { uri, querystring } = event?.Records?.[0]?.cf?.request || {}; + + const url = new URL(uri, `https://genderdysphoria.fyi`); + url.search = new URLSearchParams(querystring); const body = ` -301 Moved Permanently +Gender Dysphoria Bible -

301 Moved Permanently

-
CloudFront Lambda@Edge
+

Redirecting...

+ Click here if you are not redirected. `; @@ -15,11 +19,11 @@ exports.handler = async () => { status: '301', statusDescription: `Redirecting to www domain`, headers: { - location: [ { + location: [{ key: 'Location', - value: `https://genderdysphoria.fyi`, - } ], + value: url.toString() + }], }, - body, + body }; }; diff --git a/terraform/versions.tf b/terraform/versions.tf index 2523847..09e02b5 100644 --- a/terraform/versions.tf +++ b/terraform/versions.tf @@ -26,6 +26,6 @@ provider "namecheap" { user_name = var.namecheap.username api_user = var.namecheap.username api_key = var.namecheap.apikey - client_ip = chomp(data.http.externalip.body) + client_ip = chomp(data.http.externalip.response_body) use_sandbox = false } diff --git a/terraform/www.tf b/terraform/www.tf index 750754b..9f818e4 100644 --- a/terraform/www.tf +++ b/terraform/www.tf @@ -7,8 +7,8 @@ resource "aws_cloudfront_origin_access_identity" "origin_access_identity" { resource "aws_cloudfront_distribution" "site" { origin { - domain_name = aws_s3_bucket.src.bucket_regional_domain_name - origin_id = "S3-Website-${aws_s3_bucket.src.website_endpoint}" + domain_name = aws_s3_bucket_website_configuration.src.website_endpoint + origin_id = "S3-Website-${aws_s3_bucket_website_configuration.src.website_endpoint}" custom_origin_config { origin_protocol_policy = "http-only" @@ -30,7 +30,7 @@ resource "aws_cloudfront_distribution" "site" { default_cache_behavior { allowed_methods = ["GET", "HEAD"] cached_methods = ["GET", "HEAD"] - target_origin_id = "S3-Website-${aws_s3_bucket.src.website_endpoint}" + target_origin_id = "S3-Website-${aws_s3_bucket_website_configuration.src.website_endpoint}" forwarded_values { query_string = false