From 0c704ead39b456ad6853992e3267e034eb783798 Mon Sep 17 00:00:00 2001 From: Paulie Pena Date: Thu, 17 Feb 2022 12:06:55 -0500 Subject: [PATCH] fix #245: make `distributionPaths` configurable for `HostedZoneConfig` previous commit added the feature to `SPADeployConfig`, so this one is also adding it to `HostedZoneConfig` --- lib/spa-deploy/spa-deploy-construct.ts | 3 ++- test/cdk-spa-deploy.test.ts | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/spa-deploy/spa-deploy-construct.ts b/lib/spa-deploy/spa-deploy-construct.ts index f53e0f4..ce7e9bc 100644 --- a/lib/spa-deploy/spa-deploy-construct.ts +++ b/lib/spa-deploy/spa-deploy-construct.ts @@ -36,6 +36,7 @@ export interface HostedZoneConfig { readonly indexDoc:string, readonly errorDoc?:string, readonly cfBehaviors?: Behavior[], + readonly distributionPaths?: string[], readonly websiteFolder: string, readonly zoneName: string, readonly subdomain?: string, @@ -271,7 +272,7 @@ export class SPADeploy extends Construct { // Invalidate the cache for / and index.html when we deploy so that cloudfront serves latest site distribution, role: config.role, - distributionPaths: ['/', `/${config.indexDoc}`], + distributionPaths: config.distributionPaths || ['/', `/${config.indexDoc}`], }); new ARecord(this, 'Alias', { diff --git a/test/cdk-spa-deploy.test.ts b/test/cdk-spa-deploy.test.ts index 5622a7a..3128657 100644 --- a/test/cdk-spa-deploy.test.ts +++ b/test/cdk-spa-deploy.test.ts @@ -778,6 +778,31 @@ test('Create From Hosted Zone with Custom Role', () => { })); }); +test('Create From Hosted Zone with Custom Distribution Paths', () => { + const app = new App(); + const stack = new Stack(app, 'testStack', { + env: { + region: 'us-east-1', + account: '1234', + }, + }); + // WHEN + new SPADeploy(stack, 'spaDeploy', { encryptBucket: true }) + .createSiteFromHostedZone({ + zoneName: 'cdkspadeploy.com', + indexDoc: 'index.html', + websiteFolder: 'website', + distributionPaths: ['/images/*.png'], + }); + + const template = Template.fromStack(stack); + + // THEN + template.hasResourceProperties('Custom::CDKBucketDeployment', { + DistributionPaths: ['/images/*.png'] + }); +}); + test('Create From Hosted Zone with Error Bucket', () => { const app = new App(); const stack = new Stack(app, 'testStack', {