From 521439f8622d117b02a141b4a8144a9de16efe4e Mon Sep 17 00:00:00 2001 From: MarcEspiard <32894646+MarcEspiard@users.noreply.github.com> Date: Thu, 2 Mar 2023 23:15:55 +0000 Subject: [PATCH 1/2] Add modern image formats to SPA request function --- src/constructs/aws/SinglePageApp.ts | 4 ++-- test/unit/singlePageApp.test.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/constructs/aws/SinglePageApp.ts b/src/constructs/aws/SinglePageApp.ts index e2dc663d..e07fc014 100644 --- a/src/constructs/aws/SinglePageApp.ts +++ b/src/constructs/aws/SinglePageApp.ts @@ -43,9 +43,9 @@ export class SinglePageApp extends StaticWebsiteAbstract { * let static files pass. * * Files extensions list taken from: https://docs.aws.amazon.com/amplify/latest/userguide/redirects.html#redirects-for-single-page-web-apps-spa - * Add pdf, xml and webmanifest as well + * Add pdf, xml, webmanifest and avif as well */ - const code = `var REDIRECT_REGEX = /^[^.]+$|\\.(?!(css|gif|ico|jpg|jpeg|js|png|txt|svg|woff|woff2|ttf|map|json|xml|pdf|webmanifest)$)([^.]+$)/; + const code = `var REDIRECT_REGEX = /^[^.]+$|\\.(?!(css|gif|ico|jpg|jpeg|js|png|txt|svg|woff|woff2|ttf|map|json|xml|pdf|webmanifest|webp|avif)$)([^.]+$)/; function handler(event) { var uri = event.request.uri; diff --git a/test/unit/singlePageApp.test.ts b/test/unit/singlePageApp.test.ts index a9590950..09e029fc 100644 --- a/test/unit/singlePageApp.test.ts +++ b/test/unit/singlePageApp.test.ts @@ -29,7 +29,7 @@ describe("single page app", () => { Object { "Properties": Object { "AutoPublish": true, - "FunctionCode": "var REDIRECT_REGEX = /^[^.]+$|\\\\.(?!(css|gif|ico|jpg|jpeg|js|png|txt|svg|woff|woff2|ttf|map|json|xml|pdf|webmanifest)$)([^.]+$)/; + "FunctionCode": "var REDIRECT_REGEX = /^[^.]+$|\\\\.(?!(css|gif|ico|jpg|jpeg|js|png|txt|svg|woff|woff2|ttf|map|json|xml|pdf|webmanifest|webp|avif)$)([^.]+$)/; function handler(event) { var uri = event.request.uri; @@ -99,7 +99,7 @@ describe("single page app", () => { }); const requestFunction = computeLogicalId("landing", "RequestFunction"); expect(cfTemplate.Resources[requestFunction].Properties.FunctionCode).toMatchInlineSnapshot(` - "var REDIRECT_REGEX = /^[^.]+$|\\\\.(?!(css|gif|ico|jpg|jpeg|js|png|txt|svg|woff|woff2|ttf|map|json|xml|pdf|webmanifest)$)([^.]+$)/; + "var REDIRECT_REGEX = /^[^.]+$|\\\\.(?!(css|gif|ico|jpg|jpeg|js|png|txt|svg|woff|woff2|ttf|map|json|xml|pdf|webmanifest|webp|avif)$)([^.]+$)/; function handler(event) { var uri = event.request.uri; From e55c4ddfb84a388b3faf851d8fcf342ef78ddaca Mon Sep 17 00:00:00 2001 From: MarcEspiard <32894646+MarcEspiard@users.noreply.github.com> Date: Thu, 2 Mar 2023 23:17:41 +0000 Subject: [PATCH 2/2] Reorder so list is easier to update from AWS --- src/constructs/aws/SinglePageApp.ts | 2 +- test/unit/singlePageApp.test.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/constructs/aws/SinglePageApp.ts b/src/constructs/aws/SinglePageApp.ts index e07fc014..e11079ba 100644 --- a/src/constructs/aws/SinglePageApp.ts +++ b/src/constructs/aws/SinglePageApp.ts @@ -45,7 +45,7 @@ export class SinglePageApp extends StaticWebsiteAbstract { * Files extensions list taken from: https://docs.aws.amazon.com/amplify/latest/userguide/redirects.html#redirects-for-single-page-web-apps-spa * Add pdf, xml, webmanifest and avif as well */ - const code = `var REDIRECT_REGEX = /^[^.]+$|\\.(?!(css|gif|ico|jpg|jpeg|js|png|txt|svg|woff|woff2|ttf|map|json|xml|pdf|webmanifest|webp|avif)$)([^.]+$)/; + const code = `var REDIRECT_REGEX = /^[^.]+$|\\.(?!(css|gif|ico|jpg|jpeg|js|png|txt|svg|woff|woff2|ttf|map|json|webp|xml|pdf|webmanifest|avif)$)([^.]+$)/; function handler(event) { var uri = event.request.uri; diff --git a/test/unit/singlePageApp.test.ts b/test/unit/singlePageApp.test.ts index 09e029fc..7c602205 100644 --- a/test/unit/singlePageApp.test.ts +++ b/test/unit/singlePageApp.test.ts @@ -29,7 +29,7 @@ describe("single page app", () => { Object { "Properties": Object { "AutoPublish": true, - "FunctionCode": "var REDIRECT_REGEX = /^[^.]+$|\\\\.(?!(css|gif|ico|jpg|jpeg|js|png|txt|svg|woff|woff2|ttf|map|json|xml|pdf|webmanifest|webp|avif)$)([^.]+$)/; + "FunctionCode": "var REDIRECT_REGEX = /^[^.]+$|\\\\.(?!(css|gif|ico|jpg|jpeg|js|png|txt|svg|woff|woff2|ttf|map|json|webp|xml|pdf|webmanifest|avif)$)([^.]+$)/; function handler(event) { var uri = event.request.uri; @@ -99,7 +99,7 @@ describe("single page app", () => { }); const requestFunction = computeLogicalId("landing", "RequestFunction"); expect(cfTemplate.Resources[requestFunction].Properties.FunctionCode).toMatchInlineSnapshot(` - "var REDIRECT_REGEX = /^[^.]+$|\\\\.(?!(css|gif|ico|jpg|jpeg|js|png|txt|svg|woff|woff2|ttf|map|json|xml|pdf|webmanifest|webp|avif)$)([^.]+$)/; + "var REDIRECT_REGEX = /^[^.]+$|\\\\.(?!(css|gif|ico|jpg|jpeg|js|png|txt|svg|woff|woff2|ttf|map|json|webp|xml|pdf|webmanifest|avif)$)([^.]+$)/; function handler(event) { var uri = event.request.uri;