From fd4729230f53aefd5ff29617b99420f9a1df2398 Mon Sep 17 00:00:00 2001 From: Thijs Daniels Date: Fri, 30 Aug 2024 15:39:59 +0200 Subject: [PATCH] fix: distribution functions suffix --- .changeset/big-radios-fetch.md | 5 +++++ .../src/constructs/SiteDistribution.ts | 14 +++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) create mode 100644 .changeset/big-radios-fetch.md diff --git a/.changeset/big-radios-fetch.md b/.changeset/big-radios-fetch.md new file mode 100644 index 00000000..d2e5cc49 --- /dev/null +++ b/.changeset/big-radios-fetch.md @@ -0,0 +1,5 @@ +--- +"@codedazur/cdk-site-distribution": patch +--- + +The functions' behavior suffix is now configured correctly. diff --git a/packages/cdk-site-distribution/src/constructs/SiteDistribution.ts b/packages/cdk-site-distribution/src/constructs/SiteDistribution.ts index d444a102..0a23efa0 100644 --- a/packages/cdk-site-distribution/src/constructs/SiteDistribution.ts +++ b/packages/cdk-site-distribution/src/constructs/SiteDistribution.ts @@ -141,8 +141,8 @@ export class SiteDistribution extends Construct { domainNames: this.domain ? [this.domain] : undefined, defaultBehavior: this.behavior(), additionalBehaviors: this.props.behaviors - ? revalueObject(this.props.behaviors, ([, props]) => - this.behavior(props), + ? revalueObject(this.props.behaviors, ([pattern, props]) => + this.behavior({ pattern, ...props }), ) : undefined, }); @@ -167,7 +167,7 @@ export class SiteDistribution extends Construct { pattern?: string; } = {}): BehaviorOptions { const functions = this.createFunctions({ - pattern, + idSuffix: pattern, authentication: authentication ?? this.props.authentication, functions: functionsCode ?? this.props.functions, }); @@ -197,20 +197,20 @@ export class SiteDistribution extends Construct { } protected createFunctions({ - pattern, + idSuffix, authentication, functions, }: { - pattern: string; + idSuffix: string; } & Partial>) { const viewerRequest = this.createViewerRequestFunction({ - id: `ViewerRequestFunction-${pattern}`, + id: `ViewerRequestFunction-${idSuffix}`, authentication, code: functions?.viewerRequest, }); const viewerResponse = this.createViewerResponseFunction({ - id: `ViewerResponseFunction-${pattern}`, + id: `ViewerResponseFunction-${idSuffix}`, code: functions?.viewerResponse, });