Skip to content

Commit

Permalink
Added options for behaviour prefixes au nz etc
Browse files Browse the repository at this point in the history
  • Loading branch information
finnholland committed Oct 14, 2024
1 parent e078f01 commit 6b14c30
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 7 deletions.
8 changes: 4 additions & 4 deletions packages/prerender-proxy/lib/prerender-lambda-construct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,25 @@ export class PrerenderLambda extends Construct {

this.prerenderCheckFunction = new PrerenderCheckFunction(
this,
"PrerenderViewerRequest",
`${id}-PrerenderViewerRequest`,
props.prerenderCheckOptions
);

this.prerenderFunction = new PrerenderFunction(
this,
"PrerenderOriginRequest",
`${id}-PrerenderOriginRequest`,
props.prerenderProps
);

this.errorResponseFunction = new ErrorResponseFunction(
this,
"ErrorResponse",
`${id}-ErrorResponse`,
props.errorResponseProps
);

this.cacheControlFunction = new CloudFrontCacheControl(
this,
"PrerenderCloudFrontCacheControl",
`${id}-PrerenderCloudFrontCacheControl`,
props.cacheControlProps
);
}
Expand Down
8 changes: 6 additions & 2 deletions packages/static-hosting/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { StaticHosting, StaticHostingProps } from "./lib/static-hosting";
import {
StaticHosting,
StaticHostingProps,
remapPath,
} from "./lib/static-hosting";
import { CSP } from "./types/csp";

export { StaticHosting, StaticHostingProps, CSP };
export { StaticHosting, StaticHostingProps, CSP, remapPath };
34 changes: 33 additions & 1 deletion packages/static-hosting/lib/static-hosting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,13 @@ export interface StaticHostingProps {
*/
enableStaticFileRemap?: boolean;

/**
* Any prefixes to remapping that should be included in the path such as au or nz
*
* @default true
*/
behaviourPrefixes?: { prefix: string; edgeLambdas: EdgeLambda[] }[];

/**
* Optional additional properties for static file remap behaviours
*
Expand Down Expand Up @@ -292,7 +299,7 @@ export interface StaticHostingProps {
comment?: string;
}

interface remapPath {
export interface remapPath {
from: string;
to?: string;
behaviour?: Partial<BehaviorOptions>;
Expand Down Expand Up @@ -560,6 +567,31 @@ export class StaticHosting extends Construct {
}
}

if (enableStaticFileRemap) {
const staticFileRemapPrefixes = props.behaviourPrefixes?.map(
prefix => `${prefix.prefix}/`
) || [""];
staticFileRemapPrefixes.forEach(prefix => {
this.staticFiles.forEach(path => {
additionalBehaviors[`${prefix}*.${path}`] = {
origin: s3Origin,
viewerProtocolPolicy: ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
};
});
});
}

props.behaviourPrefixes?.forEach(prefix => {
additionalBehaviors[`${prefix.prefix}*`] = {
origin: s3Origin,
viewerProtocolPolicy: ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
edgeLambdas: prefix.edgeLambdas,
originRequestPolicy: originRequestPolicy,
cachePolicy: originCachePolicy,
responseHeadersPolicy: responseHeadersPolicy,
};
});

if (props.responseHeadersPolicies?.defaultBehaviorResponseHeaderPolicy) {
defaultBehavior.responseHeadersPolicy =
props.responseHeadersPolicies.defaultBehaviorResponseHeaderPolicy;
Expand Down

0 comments on commit 6b14c30

Please sign in to comment.