Skip to content

Commit

Permalink
feat: allow overriding CloudFront Distribution props in Webapp
Browse files Browse the repository at this point in the history
  • Loading branch information
sirius committed Aug 18, 2023
1 parent d37eb37 commit ac4603d
Show file tree
Hide file tree
Showing 3 changed files with 196 additions and 0 deletions.
177 changes: 177 additions & 0 deletions src/webapp/__tests__/__snapshots__/webapp.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions src/webapp/__tests__/webapp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { App, Duration, Stack } from "aws-cdk-lib"
import "jest-cdk-snapshot"
import { Webapp } from "../"
import { generateContentSecurityPolicyHeader } from "../security-headers"
import { SecurityPolicyProtocol } from "aws-cdk-lib/aws-cloudfront"
test("create webapp with default parameters", () => {
const app = new App()
const stack = new Stack(app, "Stack")
Expand Down Expand Up @@ -68,3 +69,14 @@ test("create webapp with domain and custom response header policy with report-on
})
expect(stack).toMatchCdkSnapshot()
})

test("create webapp with domain and override TLS configuration", () => {
const app = new App()
const stack = new Stack(app, "Stack")
new Webapp(stack, "Webapp", {
overrideDistributionProps: {
minimumProtocolVersion: SecurityPolicyProtocol.TLS_V1_2_2021,
},
})
expect(stack).toMatchCdkSnapshot()
})
7 changes: 7 additions & 0 deletions src/webapp/webapp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ export interface WebappProps {
* any values specified in securityHeaders.behaviorOverrides.
*/
overrideCloudFrontBehaviourOptions?: Partial<cloudfront.BehaviorOptions>
/**
* Distribution props overrides.
*
* Used to override default (AWS or Liflig) configuration
*/
overrideDistributionProps?: Partial<cloudfront.DistributionProps>
}

/**
Expand Down Expand Up @@ -191,6 +197,7 @@ export class Webapp extends constructs.Construct {
domainNames: props.domainNames,
errorResponses,
webAclId: props.webAclId,
...props.overrideDistributionProps,
})
}

Expand Down

0 comments on commit ac4603d

Please sign in to comment.