Skip to content

Commit

Permalink
chore: add rerouting to posthog
Browse files Browse the repository at this point in the history
  • Loading branch information
Alvin Januar committed Jun 2, 2024
1 parent 6e93e41 commit 9979acb
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
22 changes: 14 additions & 8 deletions infra/redirector.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
function handler(event) {
var request = event.request;
var uri = request.uri;
var headers = request.headers;

// Check whether the URI is missing a file name.
if (uri.endsWith("/")) {
request.uri += "index.html";
if (headers.host.value.includes("phc_9Utfol296QwPeqrpQzwtagBPYXVDjGfDl7kBGt50k5c")) {
if(uri.includes("/static")){
request.headers.host.value = headers.host.value.replace("phc_9Utfol296QwPeqrpQzwtagBPYXVDjGfDl7kBGt50k5c", "phc_9Utfol296QwPeqrpQzwtagBPYXVDjGfDl7kBGt50k5c-assets")
}
} else {
// Check whether the URI is missing a file name.
if (uri.endsWith("/")) {
request.uri += "index.html";
}
// Check whether the URI is missing a file extension.
else if (!uri.includes(".")) {
request.uri += "/index.html";
}
}
// Check whether the URI is missing a file extension.
else if (!uri.includes(".")) {
request.uri += "/index.html";
}

return request;
}
20 changes: 20 additions & 0 deletions infra/route53.tf
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,23 @@ resource "aws_route53_record" "dns_record_aaaa" {
evaluate_target_health = false
}
}

resource "aws_route53_record" "analytics_dns_record_cname" {
zone_id = data.aws_route53_zone.zone.zone_id
name = "phc_9Utfol296QwPeqrpQzwtagBPYXVDjGfDl7kBGt50k5c"
type = "CNAME"
ttl = 5
records = [
"us.i.posthog.com"
]
}

resource "aws_route53_record" "analytics_assets_dns_record_cname" {
zone_id = data.aws_route53_zone.zone.zone_id
name = "phc_9Utfol296QwPeqrpQzwtagBPYXVDjGfDl7kBGt50k5c-assets"
type = "CNAME"
ttl = 5
records = [
"us-assets.i.posthog.com"
]
}
2 changes: 1 addition & 1 deletion src/components/posthog.astro
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
(e.__SV = 1));
})(document, window.posthog || []);
posthog.init("phc_9Utfol296QwPeqrpQzwtagBPYXVDjGfDl7kBGt50k5c", {
api_host: "https://us.i.posthog.com",
api_host: "https://www.alvinjanuar.com/phc_9Utfol296QwPeqrpQzwtagBPYXVDjGfDl7kBGt50k5c",
person_profiles: "identified_only",
});
</script>

0 comments on commit 9979acb

Please sign in to comment.