Skip to content
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

Behaviour Prefixes (for CDK v2 upgrade) #1401

Merged
merged 6 commits into from
Nov 4, 2024
Merged
Changes from 1 commit
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
13 changes: 8 additions & 5 deletions packages/static-hosting/lib/static-hosting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,14 @@ export interface StaticHostingProps {
enableStaticFileRemap?: boolean;

/**
* Any prefixes to remapping that should be included in the path such as au or nz
* Overrides default behaviour paths with a prefix and takes in options to apply to each static file behaviour
Copy link
Contributor

Choose a reason for hiding this comment

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

The options don't apply to the static file behaviour do they?

*
* @default true
*/
behaviourPrefixes?: { prefix: string; edgeLambdas: EdgeLambda[] }[];
defaultBehaviourPrefixes?: {
prefix: string;
behaviourOverride: Partial<BehaviorOptions>;
}[];

/**
* Optional additional properties for static file remap behaviours
Expand Down Expand Up @@ -558,7 +561,7 @@ export class StaticHosting extends Construct {
}

if (enableStaticFileRemap) {
const staticFileRemapPrefixes = props.behaviourPrefixes?.map(
const staticFileRemapPrefixes = props.defaultBehaviourPrefixes?.map(
prefix => `${prefix.prefix}/`
) || [""];
TheOrangePuff marked this conversation as resolved.
Show resolved Hide resolved
staticFileRemapPrefixes.forEach(prefix => {
Expand All @@ -571,11 +574,11 @@ export class StaticHosting extends Construct {
});
}

props.behaviourPrefixes?.forEach(prefix => {
props.defaultBehaviourPrefixes?.forEach(prefix => {
TheOrangePuff marked this conversation as resolved.
Show resolved Hide resolved
additionalBehaviors[`${prefix.prefix}*`] = {
origin: s3Origin,
viewerProtocolPolicy: ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
edgeLambdas: prefix.edgeLambdas,
edgeLambdas: prefix.behaviourOverride.edgeLambdas,
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of just passing the edge lambda you can do this:

      additionalBehaviors[`${prefix.prefix}*`] = {
        origin: s3Origin,
        viewerProtocolPolicy: ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
        originRequestPolicy: originRequestPolicy,
        cachePolicy: originCachePolicy,
        responseHeadersPolicy: responseHeadersPolicy,
        ...prefix.behaviourOverride,
      };

Because that will then allow you to override any of the properties if you need

Copy link
Contributor

Choose a reason for hiding this comment

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

@finn-holland-aligent this one hasn't been resolved yet

originRequestPolicy: originRequestPolicy,
cachePolicy: originCachePolicy,
responseHeadersPolicy: responseHeadersPolicy,
Expand Down
Loading