diff --git a/packages/static-hosting/lib/static-hosting.ts b/packages/static-hosting/lib/static-hosting.ts index cf049143..b16388b9 100644 --- a/packages/static-hosting/lib/static-hosting.ts +++ b/packages/static-hosting/lib/static-hosting.ts @@ -140,7 +140,7 @@ export interface StaticHostingProps { enableStaticFileRemap?: boolean; /** - * Overrides default behaviour paths with a prefix and takes in options to apply to each static file behaviour + * Overrides default behaviour paths with a prefix and takes in behviour options to apply on the prefix behaviour * * @default true */ @@ -357,12 +357,12 @@ export class StaticHosting extends Construct { const s3LoggingBucket = props.enableS3AccessLogging ? new Bucket(this, "S3LoggingBucket", { - bucketName: `${siteName}-s3-access-logs`, - encryption: BucketEncryption.S3_MANAGED, - blockPublicAccess: BlockPublicAccess.BLOCK_ALL, - removalPolicy: RemovalPolicy.RETAIN, - enforceSSL: enforceSSL, - }) + bucketName: `${siteName}-s3-access-logs`, + encryption: BucketEncryption.S3_MANAGED, + blockPublicAccess: BlockPublicAccess.BLOCK_ALL, + removalPolicy: RemovalPolicy.RETAIN, + enforceSSL: enforceSSL, + }) : undefined; if (s3LoggingBucket) { @@ -397,8 +397,8 @@ export class StaticHosting extends Construct { const publisherUser = props.createPublisherUser !== false ? new User(this, "PublisherUser", { - userName: `publisher-${siteName}`, - }) + userName: `publisher-${siteName}`, + }) : undefined; if (publisherUser) { @@ -430,12 +430,12 @@ export class StaticHosting extends Construct { const loggingBucket = props.enableCloudFrontAccessLogging ? new Bucket(this, "LoggingBucket", { - bucketName: `${siteName}-access-logs`, - encryption: BucketEncryption.S3_MANAGED, - blockPublicAccess: BlockPublicAccess.BLOCK_ALL, - removalPolicy: RemovalPolicy.RETAIN, - enforceSSL: enforceSSL, - }) + bucketName: `${siteName}-access-logs`, + encryption: BucketEncryption.S3_MANAGED, + blockPublicAccess: BlockPublicAccess.BLOCK_ALL, + removalPolicy: RemovalPolicy.RETAIN, + enforceSSL: enforceSSL, + }) : undefined; if (loggingBucket) { @@ -576,12 +576,12 @@ export class StaticHosting extends Construct { props.defaultBehaviourPrefixes?.forEach(prefix => { additionalBehaviors[`${prefix.prefix}*`] = { - origin: s3Origin, - viewerProtocolPolicy: ViewerProtocolPolicy.REDIRECT_TO_HTTPS, + origin: prefix.behaviourOverride.origin ?? s3Origin, + viewerProtocolPolicy: prefix.behaviourOverride.viewerProtocolPolicy ?? ViewerProtocolPolicy.REDIRECT_TO_HTTPS, edgeLambdas: prefix.behaviourOverride.edgeLambdas, - originRequestPolicy: originRequestPolicy, - cachePolicy: originCachePolicy, - responseHeadersPolicy: responseHeadersPolicy, + originRequestPolicy: prefix.behaviourOverride.originRequestPolicy ?? originRequestPolicy, + cachePolicy: prefix.behaviourOverride.cachePolicy ?? originCachePolicy, + responseHeadersPolicy: prefix.behaviourOverride.responseHeadersPolicy ?? responseHeadersPolicy, }; }); @@ -701,9 +701,9 @@ export class StaticHosting extends Construct { const cspEntries = explicit ? csp : { - "default-src": [], - ...csp, - }; + "default-src": [], + ...csp, + }; return Object.entries(cspEntries) .reduce((prevCspHeader, [cspType, cspHeaders]) => {