Skip to content

Commit 2eaca65

Browse files
committed
fix leaderboard cors
1 parent 3b26fc4 commit 2eaca65

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

aws/aws.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,20 @@ func NewAwsStack(scope constructs.Construct, id string, props *ClockeryStackProp
4343

4444
api := awsapigateway.NewRestApi(stack, jsii.String("ClockeryLeaderboardApi"), &awsapigateway.RestApiProps{
4545
RestApiName: jsii.String("ClockeryLeaderboardApi"),
46+
DefaultCorsPreflightOptions: &awsapigateway.CorsOptions{
47+
AllowOrigins: awsapigateway.Cors_ALL_ORIGINS(),
48+
AllowMethods: awsapigateway.Cors_ALL_METHODS(),
49+
},
4650
})
4751

4852
resource := api.Root().AddResource(
4953
jsii.String("leaderboard"),
50-
&awsapigateway.ResourceOptions{},
54+
&awsapigateway.ResourceOptions{
55+
DefaultCorsPreflightOptions: &awsapigateway.CorsOptions{
56+
AllowOrigins: awsapigateway.Cors_ALL_ORIGINS(),
57+
AllowMethods: awsapigateway.Cors_ALL_METHODS(),
58+
},
59+
},
5160
)
5261

5362
resource.AddMethod(

aws/lambda/leaderboard/get-all/get.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ func HandleRequest(ctx context.Context) (*events.APIGatewayProxyResponse, error)
6060
}
6161

6262
return &events.APIGatewayProxyResponse{
63+
Headers: map[string]string{
64+
"Access-Control-Allow-Origin": "*",
65+
},
6366
StatusCode: 200,
6467
Body: string(body),
6568
}, nil

aws/lambda/leaderboard/post/post.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ func HandleRequest(ctx context.Context, req events.APIGatewayProxyRequest) (*eve
7474
}
7575

7676
return &events.APIGatewayProxyResponse{
77+
Headers: map[string]string{
78+
"Access-Control-Allow-Origin": "*",
79+
},
7780
StatusCode: 200,
7881
Body: string(body),
7982
}, nil

0 commit comments

Comments
 (0)