Skip to content

Commit

Permalink
Merge pull request #1376 from aligent/fix/DO-1660_update_viewer_proto…
Browse files Browse the repository at this point in the history
…col_policy

Fix/do 1660 update viewer protocol policy
  • Loading branch information
crispy101 authored May 23, 2024
2 parents d1b4d5b + 30512db commit 4d4e503
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions packages/static-hosting/lib/static-hosting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export interface StaticHostingProps {
* Paths to remap on the default behaviour. For example you might remap deployed_sitemap.xml -> sitemap.xml
* Created a behaviour in CloudFront to handle the remap. If the paths are different
* it will also deploy a Lambda@Edge function to perform the required remap.
* The "to" path is optional, and the Lambda@Edge function will not be deployed if not provided.
*
* @default undefined
*/
Expand Down Expand Up @@ -276,7 +277,7 @@ export interface StaticHostingProps {

interface remapPath {
from: string;
to: string;
to?: string;
}

export interface ResponseHeaderMappings {
Expand Down Expand Up @@ -519,6 +520,7 @@ export class StaticHosting extends Construct {
for (const path of props.remapPaths) {
additionalBehaviors[path.from] = {
origin: s3Origin,
viewerProtocolPolicy: ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
edgeLambdas: this.createRemapBehavior(path.from, path.to),
};
}
Expand Down Expand Up @@ -610,12 +612,12 @@ export class StaticHosting extends Construct {
}
}

private createRemapBehavior(from: string, to: string): EdgeLambda[] {
private createRemapBehavior(from: string, to?: string): EdgeLambda[] {
const lambdas: EdgeLambda[] = [];

// If the remap is to a different path, create a Lambda@Edge function to handle this
// Remove special characters from path
if (from.replace(/\*$/, "") !== to) {
if (to && from.replace(/\*$/, "") !== to) {
const id = from.replace(/[&/\\#,+()$~%'":*?<>{}]/g, "-");

const remapFunction = new PathRemapFunction(
Expand Down
2 changes: 1 addition & 1 deletion packages/static-hosting/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aligent/cdk-static-hosting",
"version": "2.3.1",
"version": "2.3.4",
"main": "index.js",
"license": "GPL-3.0-only",
"homepage": "https://github.com/aligent/aws-cdk-static-hosting-stack#readme",
Expand Down

0 comments on commit 4d4e503

Please sign in to comment.