Skip to content

Commit

Permalink
fix(aws-cloudfront): check for undefined and determining of the defau…
Browse files Browse the repository at this point in the history
…ltRootObject prop is set or not (#801)

* Check specifically for undefined and determining of the defaultRootObject prop is set or not.

* Add testing to verify valid empty roots
  • Loading branch information
ZeldoKavira authored and Elad Ben-Israel committed Sep 28, 2018
1 parent 60ef847 commit 156f043
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-cloudfront/lib/web_distribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ export class CloudFrontWebDistribution extends cdk.Construct {
const distributionConfig: cloudformation.DistributionResource.DistributionConfigProperty = {
comment: props.comment,
enabled: true,
defaultRootObject: props.defaultRootObject || "index.html",
defaultRootObject: props.defaultRootObject !== undefined ? props.defaultRootObject : "index.html",
httpVersion: props.httpVersion || HttpVersion.HTTP2,
priceClass: props.priceClass || PriceClass.PriceClass100,
ipv6Enabled: props.enableIpV6 || true,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"Resources": {
"AnAmazingWebsiteProbablyCFDistribution47E3983B": {
"Type": "AWS::CloudFront::Distribution",
"Properties": {
"DistributionConfig": {
"CacheBehaviors": [],
"DefaultCacheBehavior": {
"AllowedMethods": [
"GET",
"HEAD"
],
"CachedMethods": [
"GET",
"HEAD"
],
"ForwardedValues": {
"Cookies": {
"Forward": "none"
},
"QueryString": false
},
"TargetOriginId": "origin1",
"ViewerProtocolPolicy": "redirect-to-https"
},
"DefaultRootObject": "",
"Enabled": true,
"HttpVersion": "http2",
"IPV6Enabled": true,
"Origins": [
{
"CustomOriginConfig": {
"HTTPPort": 80,
"HTTPSPort": 443,
"OriginKeepaliveTimeout": 5,
"OriginProtocolPolicy": "https-only",
"OriginReadTimeout": 30,
"OriginSSLProtocols": [
"TLSv1.2"
]
},
"DomainName": "brelandm.a2z.com",
"Id": "origin1",
"OriginCustomHeaders": [
{
"HeaderName": "X-Custom-Header",
"HeaderValue": "somevalue"
}
]
}
],
"PriceClass": "PriceClass_100",
"ViewerCertificate": {
"CloudFrontDefaultCertificate": true
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

import cdk = require('@aws-cdk/cdk');
import cloudfront = require('../lib');

const app = new cdk.App(process.argv);

const stack = new cdk.Stack(app, 'aws-cdk-cloudfront-custom');

new cloudfront.CloudFrontWebDistribution(stack, 'AnAmazingWebsiteProbably', {
originConfigs: [
{
originHeaders: {
"X-Custom-Header": "somevalue",
},
customOriginSource: {
domainName: "brelandm.a2z.com",
},
behaviors: [
{
isDefaultBehavior: true,
}
],
}
],
defaultRootObject: ''
});

process.stdout.write(app.run());

1 comment on commit 156f043

@RomainMuller
Copy link
Contributor

@RomainMuller RomainMuller commented on 156f043 Oct 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Due to a release issue having resulted in a need to re-tag, despite this commit appears before the v0.10.0 tag, it is only included in the GitHub release, and not in the npm, mvn or nuget releases.

It will be part of the next release, however.

Please sign in to comment.