1- variable "allowed_origins" {
2- type = " list"
3- default = [" localhost:3333" , " deckdeckgo.com" ]
4- }
5-
61resource "aws_api_gateway_rest_api" "lambda-api" {
72 name = " deckdeckgo-handler-rest-api"
83}
94
10- resource "aws_api_gateway_resource" "proxy" {
5+ resource "aws_api_gateway_resource" "proxy-api " {
116 rest_api_id = " ${ aws_api_gateway_rest_api . lambda-api . id } "
127 parent_id = " ${ aws_api_gateway_rest_api . lambda-api . root_resource_id } "
8+ path_part = " api"
9+ }
10+
11+ resource "aws_api_gateway_resource" "proxy" {
12+ rest_api_id = " ${ aws_api_gateway_rest_api . lambda-api . id } "
13+ parent_id = " ${ aws_api_gateway_resource . proxy-api . id } "
1314 path_part = " {proxy+}"
1415}
1516
@@ -20,6 +21,7 @@ resource "aws_api_gateway_method" "proxy" {
2021 authorization = " NONE"
2122}
2223
24+ # XXX: when redeploying, tweak the stage name
2325resource "aws_api_gateway_integration" "lambda-api" {
2426 rest_api_id = " ${ aws_api_gateway_rest_api . lambda-api . id } "
2527 resource_id = " ${ aws_api_gateway_method . proxy . resource_id } "
@@ -33,6 +35,8 @@ resource "aws_api_gateway_integration" "lambda-api" {
3335resource "aws_api_gateway_deployment" "lambda-api" {
3436 depends_on = [
3537 " aws_api_gateway_integration.lambda-api" ,
38+ " aws_api_gateway_resource.proxy-api" ,
39+ " aws_api_gateway_resource.proxy" ,
3640 ]
3741
3842 rest_api_id = " ${ aws_api_gateway_rest_api . lambda-api . id } "
@@ -103,7 +107,7 @@ resource "aws_api_gateway_integration_response" "options_integration_response" {
103107 response_parameters = {
104108 " method.response.header.Access-Control-Allow-Headers" = " 'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'"
105109 " method.response.header.Access-Control-Allow-Methods" = " 'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'"
106- " method.response.header.Access-Control-Allow-Origin" = " '${ join ( " , " ,var . allowed_origins ) } '"
110+ " method.response.header.Access-Control-Allow-Origin" = " '* '"
107111 }
108112}
109113
0 commit comments