Skip to content
This repository was archived by the owner on Feb 6, 2024. It is now read-only.
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: 11 additions & 7 deletions infra/api_gateway.tf
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
variable "allowed_origins" {
type = "list"
default = ["localhost:3333", "deckdeckgo.com"]
}

resource "aws_api_gateway_rest_api" "lambda-api" {
name = "deckdeckgo-handler-rest-api"
}

resource "aws_api_gateway_resource" "proxy" {
resource "aws_api_gateway_resource" "proxy-api" {
rest_api_id = "${aws_api_gateway_rest_api.lambda-api.id}"
parent_id = "${aws_api_gateway_rest_api.lambda-api.root_resource_id}"
path_part = "api"
}

resource "aws_api_gateway_resource" "proxy" {
rest_api_id = "${aws_api_gateway_rest_api.lambda-api.id}"
parent_id = "${aws_api_gateway_resource.proxy-api.id}"
path_part = "{proxy+}"
}

Expand All @@ -20,6 +21,7 @@ resource "aws_api_gateway_method" "proxy" {
authorization = "NONE"
}

# XXX: when redeploying, tweak the stage name
resource "aws_api_gateway_integration" "lambda-api" {
rest_api_id = "${aws_api_gateway_rest_api.lambda-api.id}"
resource_id = "${aws_api_gateway_method.proxy.resource_id}"
Expand All @@ -33,6 +35,8 @@ resource "aws_api_gateway_integration" "lambda-api" {
resource "aws_api_gateway_deployment" "lambda-api" {
depends_on = [
"aws_api_gateway_integration.lambda-api",
"aws_api_gateway_resource.proxy-api",
"aws_api_gateway_resource.proxy",
]

rest_api_id = "${aws_api_gateway_rest_api.lambda-api.id}"
Expand Down Expand Up @@ -103,7 +107,7 @@ resource "aws_api_gateway_integration_response" "options_integration_response" {
response_parameters = {
"method.response.header.Access-Control-Allow-Headers" = "'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'"
"method.response.header.Access-Control-Allow-Methods" = "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'"
"method.response.header.Access-Control-Allow-Origin" = "'${join(",",var.allowed_origins)}'"
"method.response.header.Access-Control-Allow-Origin" = "'*'"
}
}

Expand Down
3 changes: 2 additions & 1 deletion infra/handler/src/DeckGo/Handler.hs
Original file line number Diff line number Diff line change
Expand Up @@ -356,10 +356,11 @@ instance Aeson.FromJSON Slide where
instance Aeson.ToJSON Slide where
toJSON = Aeson.Object . toJSONObject

type API =
type API = "api" :> (
"users" :> UsersAPI :<|>
"decks" :> DecksAPI :<|>
"decks" :> SlidesAPI
)

api :: Proxy API
api = Proxy
Expand Down