Skip to content

fix #245: make distributionPaths configurable #444

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/spa-deploy/spa-deploy-construct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface SPADeployConfig {
readonly certificateARN?: string,
readonly cfBehaviors?: Behavior[],
readonly cfAliases?: string[],
readonly distributionPaths?: string[],
readonly exportWebsiteUrlOutput?:boolean,
readonly exportWebsiteUrlName?: string,
readonly blockPublicAccess?:s3.BlockPublicAccess
Expand All @@ -35,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,
Expand Down Expand Up @@ -235,7 +237,7 @@ export class SPADeploy extends Construct {
destinationBucket: websiteBucket,
// Invalidate the cache for / and index.html when we deploy so that cloudfront serves latest site
distribution,
distributionPaths: ['/', `/${config.indexDoc}`],
distributionPaths: config.distributionPaths || ['/', `/${config.indexDoc}`],
role: config.role,
});

Expand Down Expand Up @@ -270,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', {
Expand Down
46 changes: 46 additions & 0 deletions test/cdk-spa-deploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,27 @@ test('Cloudfront With Custom Defined Behaviors', () => {
}));
});

test('Cloudfront With Custom Distribution Paths', () => {
const stack = new Stack();
// WHEN
const deploy = new SPADeploy(stack, 'spaDeploy');

deploy.createSiteWithCloudfront({
indexDoc: 'index.html',
websiteFolder: 'website',
certificateARN: 'arn:1234',
cfAliases: ['www.test.com'],
distributionPaths: ['/images/*.png'],
});

const template = Template.fromStack(stack);

// THEN
template.hasResourceProperties('Custom::CDKBucketDeployment', {
DistributionPaths: ['/images/*.png']
});
});

test('Cloudfront With Custom Security Policy', () => {
const stack = new Stack();
// WHEN
Expand Down Expand Up @@ -757,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', {
Expand Down