Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add redirect to mm snap for dev #125

Merged
merged 2 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading