Skip to content

Commit 2a2c518

Browse files
committed
try with proxy
1 parent 16806bb commit 2a2c518

File tree

3 files changed

+5
-36
lines changed

3 files changed

+5
-36
lines changed

src/api.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ import {
22
AuthorizationType,
33
CfnAuthorizer,
44
Cors,
5-
IResource,
6-
MockIntegration,
7-
PassthroughBehavior,
85
RestApi,
96
} from 'aws-cdk-lib/aws-apigateway'
107
import { UserPool } from 'aws-cdk-lib/aws-cognito'
@@ -21,6 +18,9 @@ export const createAPI = (props: {
2118
},
2219
defaultCorsPreflightOptions: {
2320
allowOrigins: Cors.ALL_ORIGINS,
21+
allowMethods: Cors.ALL_METHODS,
22+
allowHeaders: ['*'],
23+
allowCredentials: true,
2424
},
2525
})
2626

src/index.ts

-11
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,6 @@ export default class AwsGoStack extends Stack {
9292

9393
resource.addMethod(api.method, createLambdaIntegration({ lambdaFn }), {
9494
...methodOptions,
95-
methodResponses: [
96-
{
97-
statusCode: '200',
98-
responseParameters: {
99-
'method.response.header.Access-Control-Allow-Headers': true,
100-
'method.response.header.Access-Control-Allow-Methods': true,
101-
'method.response.header.Access-Control-Allow-Credentials': true,
102-
'method.response.header.Access-Control-Allow-Origin': true,
103-
},
104-
},
105-
],
10695
})
10796
})
10897
}

src/integration.ts

+2-22
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,8 @@
1-
import {
2-
LambdaIntegration,
3-
PassthroughBehavior,
4-
} from 'aws-cdk-lib/aws-apigateway'
1+
import { LambdaIntegration } from 'aws-cdk-lib/aws-apigateway'
52
import { IFunction } from 'aws-cdk-lib/aws-lambda'
63

74
export const createLambdaIntegration = (props: { lambdaFn: IFunction }) => {
85
return new LambdaIntegration(props.lambdaFn, {
9-
proxy: false,
10-
integrationResponses: [
11-
{
12-
statusCode: '200',
13-
responseParameters: {
14-
'method.response.header.Access-Control-Allow-Headers':
15-
"'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token,X-Amz-User-Agent'",
16-
'method.response.header.Access-Control-Allow-Origin': "'*'",
17-
'method.response.header.Access-Control-Allow-Credentials': "'false'",
18-
'method.response.header.Access-Control-Allow-Methods':
19-
"'OPTIONS,GET,PUT,POST,DELETE'",
20-
},
21-
},
22-
],
23-
passthroughBehavior: PassthroughBehavior.NEVER,
24-
requestTemplates: {
25-
'application/json': '{"statuscode": 200}',
26-
},
6+
proxy: true,
277
})
288
}

0 commit comments

Comments
 (0)