Skip to content

Commit

Permalink
DO-1531: make default behaviour lambdas optional
Browse files Browse the repository at this point in the history
* add viewer protocol policy to redirect http to
https
  • Loading branch information
gowrizrh committed Sep 26, 2023
1 parent 7f13a35 commit 2565645
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/static-hosting/lib/static-hosting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export interface StaticHostingProps {
responseHeadersPolicies?: ResponseHeaderMappings;
additionalBehaviors?: Record<string, BehaviorOptions>;
errorResponsePagePath?: string;
defaultBehaviorEdgeLambdas: EdgeLambda[];
defaultBehaviorEdgeLambdas?: EdgeLambda[];

/**
* After switching constructs, you need to maintain the same logical ID
Expand Down Expand Up @@ -147,6 +147,7 @@ export class StaticHosting extends Construct {
const enableStaticFileRemap = props.enableStaticFileRemap !== false;
const defaultRootObject = props.defaultRootObject ?? "/index.html";
const errorResponsePagePath = props.errorResponsePagePath ?? "/index.html";
const defaultBehaviorEdgeLambdas = props.defaultBehaviorEdgeLambdas ?? [];
const disableCSP = props.disableCSP === true;

const domainNames: Array<string> = props.extraDistributionCnames
Expand Down Expand Up @@ -295,7 +296,7 @@ export class StaticHosting extends Construct {
const defaultBehavior: Writeable<BehaviorOptions> = {
origin: s3Origin,
viewerProtocolPolicy: ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
edgeLambdas: props.defaultBehaviorEdgeLambdas,
edgeLambdas: defaultBehaviorEdgeLambdas,
originRequestPolicy: originRequestPolicy,
cachePolicy: originCachePolicy,
responseHeadersPolicy: responseHeadersPolicy,
Expand All @@ -319,7 +320,10 @@ export class StaticHosting extends Construct {

if (enableStaticFileRemap) {
for (const path of this.staticFiles) {
additionalBehaviors[`*.${path}`] = { origin: s3Origin };
additionalBehaviors[`*.${path}`] = {
origin: s3Origin,
viewerProtocolPolicy: ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
};
}
}

Expand Down

0 comments on commit 2565645

Please sign in to comment.