Skip to content

Commit

Permalink
fix: add redirection on dev (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
stanleyyconsensys authored Aug 30, 2023
1 parent b1fddc6 commit e59dde5
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
18 changes: 18 additions & 0 deletions terraform/live/functions/redirect-mm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
function handler(event) {
var request = event.request;

if (request.uri == "/starknet" || request.uri == "/starknet/") {
request.uri = request.uri.replace(/.*starknet.*/,'/starknet/index.html');
return request;
}
if (request.uri.startsWith("/starknet")) {
return request;
}
return {
statusCode: 302,
statusDescription: 'Moved Temporarily',
headers: {
'location': { "value": `https://metamask.io/snaps` }
}
};
}
19 changes: 19 additions & 0 deletions terraform/live/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ locals {
event_type = "viewer-response"
}
}

cloudfront_functions_new = {
redirect = {
arn = aws_cloudfront_function.starknet_redirect_mm.arn
event_type = "viewer-request"
}
headers = {
arn = aws_cloudfront_function.starknet_add_header.arn
event_type = "viewer-response"
}
}
}

resource "aws_route53_zone" "main" {
Expand Down Expand Up @@ -85,6 +96,14 @@ module "snaps_cert" {
## Cloufront configurations
#############

resource "aws_cloudfront_function" "starknet_redirect_mm" {
name = "starknet-snap-redirect-mm"
runtime = "cloudfront-js-1.0"
comment = "starknet-snap-redirect-mm"
publish = true
code = file("${path.module}/functions/redirect-mm.js")
}

resource "aws_cloudfront_function" "starknet_redirect" {
name = "starknet-snap-redirect"
runtime = "cloudfront-js-1.0"
Expand Down

0 comments on commit e59dde5

Please sign in to comment.