Skip to content
This repository was archived by the owner on Feb 6, 2024. It is now read-only.

Commit a23c311

Browse files
authored
Merge pull request #121 from deckgo/nm-api
feat: move API behind /api
2 parents d2f37cf + 1455eff commit a23c311

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

infra/api_gateway.tf

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
variable "allowed_origins" {
2-
type = "list"
3-
default = ["localhost:3333", "deckdeckgo.com"]
4-
}
5-
61
resource "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
2325
resource "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" {
3335
resource "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

infra/handler/src/DeckGo/Handler.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,10 +356,11 @@ instance Aeson.FromJSON Slide where
356356
instance Aeson.ToJSON Slide where
357357
toJSON = Aeson.Object . toJSONObject
358358

359-
type API =
359+
type API = "api" :> (
360360
"users" :> UsersAPI :<|>
361361
"decks" :> DecksAPI :<|>
362362
"decks" :> SlidesAPI
363+
)
363364

364365
api :: Proxy API
365366
api = Proxy

0 commit comments

Comments
 (0)