From 09e951fb9e77cc57ce885ae1e550b870c3402550 Mon Sep 17 00:00:00 2001 From: Brett Date: Sun, 14 Apr 2024 13:58:54 +0930 Subject: [PATCH] docs: fix lambda-function-url example's HttpApi CORS --- .../packages/cdk/lib/constructs/ExpressApi.ts | 30 ++++--------------- 1 file changed, 6 insertions(+), 24 deletions(-) diff --git a/examples/lambda-function-url/packages/cdk/lib/constructs/ExpressApi.ts b/examples/lambda-function-url/packages/cdk/lib/constructs/ExpressApi.ts index 7874ea46..ca3bcae2 100644 --- a/examples/lambda-function-url/packages/cdk/lib/constructs/ExpressApi.ts +++ b/examples/lambda-function-url/packages/cdk/lib/constructs/ExpressApi.ts @@ -164,36 +164,18 @@ export default class ExpressApi extends Construct { }) } - const api = new HttpApi(this, 'HttpApi', { - apiName: `Todo-${getEnvironmentName(this.node)}`, - // corsPreflight: { - // allowHeaders: [ - // // Must explicitly specify Authorization, othwerise maxAge isn't respected and preflight - // // will be sent on all requests https://twitter.com/annevk/status/1422959365846351875 - // // Unfortunately, there appears to be a bug in API Gateway where it doesn't return the - // // correct preflight response headers when 'authorization' is defined. - // 'authorization', - // // '*', - // ], - // allowMethods: [CorsHttpMethod.ANY], - // allowOrigins: Cors.ALL_ORIGINS, - // maxAge: Duration.hours(24), // Firefox caps at 24 hours; Chromium caps at 2 hours - // }, - defaultDomainMapping: domainResource - ? { - domainName: domainResource, - } - : undefined, - }) + const api = new HttpApi(this, 'HttpApi') api.addRoutes({ path: '/{proxy+}', integration, authorizer, - // Must exclude OPTIONS so that CORS Preflight requests don't get sent through to Lambda, - // and instead are fulfilled by API Gateway - // methods: [HttpMethod.HEAD, HttpMethod.GET, HttpMethod.POST, HttpMethod.PATCH, HttpMethod.PUT, HttpMethod.DELETE], methods: [HttpMethod.ANY], }) + api.addRoutes({ + path: '/{proxy+}', + integration, + methods: [HttpMethod.OPTIONS], + }) // this.enableApiAccessLogs({ api })