Skip to content

Commit 04a18a2

Browse files
committed
Add cors handling to rest api
1 parent e25edab commit 04a18a2

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

cdk/quiz_app/quiz_app_stack.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import json
2-
from pathlib import Path
3-
41
import aws_cdk
52
from aws_cdk import (
63
Stack,
@@ -131,7 +128,18 @@ def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
131128
)
132129

133130
# create rest api
134-
rest_api = apigateway.RestApi(self, "QuizAPI")
131+
# TODO: this is a circular dependency as we need to know the cloudfront
132+
# domain name from the FrontendStack to add a specific origin, but the
133+
# FrontendStack depends on the APIGW URL from this stack
134+
rest_api = apigateway.RestApi(
135+
self,
136+
"QuizAPI",
137+
default_cors_preflight_options=apigateway.CorsOptions(
138+
allow_origins=apigateway.Cors.ALL_ORIGINS,
139+
allow_methods=apigateway.Cors.ALL_METHODS,
140+
),
141+
)
142+
135143
endpoints = [
136144
("getquiz", "GET", "GetQuizFunction"),
137145
("createquiz", "POST", "CreateQuizFunction"),
@@ -256,7 +264,6 @@ def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
256264
role=state_machine_role,
257265
)
258266

259-
260267
# set up lambda permissions
261268
quizzes_table.grant_write_data(functions["CreateQuizFunction"])
262269
# TODO: createquizfunction should be able to write to QuizzesWriteFailures

0 commit comments

Comments
 (0)