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 d405d2f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
36 changes: 28 additions & 8 deletions infra/redirector.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,34 @@ function handler(event) {
var request = event.request;
var uri = request.uri;

// Check whether the URI is missing a file name.
if (uri.endsWith("/")) {
request.uri += "index.html";
if (uri.includes("/phc_9Utfol296QwPeqrpQzwtagBPYXVDjGfDl7kBGt50k5c")) {
let newURI = uri.split("/phc_9Utfol296QwPeqrpQzwtagBPYXVDjGfDl7kBGt50k5c")[1]
if(uri.includes("/static")){
return {
statusCode: 301,
statusDescription: "Moved Permanently",
headers: {
location: { value: "https://us-assets.i.posthog.com" + newURI },
},
}
} else {
return {
statusCode: 301,
statusDescription: "Moved Permanently",
headers: {
location: { value: "https://us.i.posthog.com" + newURI },
},
}
}
} 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;
}
2 changes: 1 addition & 1 deletion infra/route53.tf
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ resource "aws_route53_record" "dns_record_aaaa" {
zone_id = aws_cloudfront_distribution.s3_distribution.hosted_zone_id
evaluate_target_health = false
}
}
}
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 d405d2f

Please sign in to comment.