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

Fix/do 1660 update viewer protocol policy #1376

Merged
merged 4 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
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 (from.replace(/\*$/, "") !== to && to) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you flip these conditions around so it checks if to is falsey first?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, done.

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
Loading