Repository: pwrdrvr/microapps-core (language: python)

Issue:
Demo - Clean up CloudFront Behaviors
- [x] Remove `*/*/api/*`
- [x] Remove `*/*/static/*`
- [x] Modify `*/*/` to `*`
- [x] Fix PR URLs for Prefix deploy


Discussion / hints:

Fix patch:
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 4ce6ab64..36656973 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -77,7 +77,7 @@ jobs:
       - build
     environment:
       name: ghpublic
-      url: https://${{ steps.getCDKExports.outputs.edgeDomain }}/release/
+      url: https://${{ steps.getCDKExports.outputs.edgeDomain }}${{ steps.getCDKExports.outputs.prefix }}/release/
     permissions:
       contents: read
       id-token: write
@@ -144,6 +144,7 @@ jobs:
       - name: Get CDK Exports
         id: getCDKExports
         run: |
+          echo "::set-output name=prefix::"${PREFIX}
           echo "::set-output name=edgeDomain::"$(aws cloudformation list-exports --query "Exports[?Name==\`${{ matrix.deployName }}-ghpublic-${NODE_ENV}${{ needs.build.outputs.prSuffix }}-edge-domain-name\`].Value" --no-paginate --output text)
           echo "EDGE_DOMAIN="$(aws cloudformation list-exports --query "Exports[?Name==\`${{ matrix.deployName }}-ghpublic-${NODE_ENV}${{ needs.build.outputs.prSuffix }}-edge-domain-name\`].Value" --no-paginate --output text) >> $GITHUB_ENV
           echo "DEPLOYER_LAMBDA_NAME="$(aws cloudformation list-exports --query "Exports[?Name==\`${{ matrix.deployName }}-ghpublic-${NODE_ENV}${{ needs.build.outputs.prSuffix }}-deployer-func-name\`].Value" --no-paginate --output text) >> $GITHUB_ENV
diff --git a/packages/microapps-cdk/src/MicroAppsCF.ts b/packages/microapps-cdk/src/MicroAppsCF.ts
index 467e1d8c..ff643551 100644
--- a/packages/microapps-cdk/src/MicroAppsCF.ts
+++ b/packages/microapps-cdk/src/MicroAppsCF.ts
@@ -174,13 +174,6 @@ export class MicroAppsCF extends cdk.Construct implements IMicroAppsCF {
     //
     // Add Behaviors
     //
-    const apiGwyBehaviorOptions: cf.AddBehaviorOptions = {
-      allowedMethods: cf.AllowedMethods.ALLOW_ALL,
-      cachePolicy: cf.CachePolicy.CACHING_DISABLED,
-      compress: true,
-      originRequestPolicy: apigwyOriginRequestPolicy,
-      viewerProtocolPolicy: cf.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
-    };
     const s3BehaviorOptions: cf.AddBehaviorOptions = {
       allowedMethods: cf.AllowedMethods.ALLOW_GET_HEAD_OPTIONS,
       cachePolicy: cf.CachePolicy.CACHING_OPTIMIZED,
@@ -188,8 +181,9 @@ export class MicroAppsCF extends cdk.Construct implements IMicroAppsCF {
       originRequestPolicy: cf.OriginRequestPolicy.CORS_S3_ORIGIN,
       viewerProtocolPolicy: cf.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
     };
-    const apiGwyVersionRootBehaviorOptions: cf.AddBehaviorOptions = {
-      allowedMethods: cf.AllowedMethods.ALLOW_GET_HEAD_OPTIONS,
+    const apiGwyBehaviorOptions: cf.AddBehaviorOptions = {
+      allowedMethods: cf.AllowedMethods.ALLOW_ALL,
+      // TODO: Caching needs to be set by the app response
       cachePolicy: cf.CachePolicy.CACHING_DISABLED,
       compress: true,
       originRequestPolicy: apigwyOriginRequestPolicy,
@@ -197,31 +191,20 @@ export class MicroAppsCF extends cdk.Construct implements IMicroAppsCF {
     };
 
     //
-    // Setup Routes
-    // Pull to the API first, then pull to S3 if it contains /static/
-    // Pull anything under /appName/x.y.z/ folder with '.' in file name to S3
-    // Let everything else fall through to the API Gateway
+    // All static assets are assumed to have a dot in them
     //
-    distro.addBehavior(
-      posixPath.join(rootPathPrefix, '/*/*/api/*'),
-      apiGwyOrigin,
-      apiGwyBehaviorOptions,
-    );
-    distro.addBehavior(
-      posixPath.join(rootPathPrefix, '/*/*/static/*'),
-      bucketAppsOrigin,
-      s3BehaviorOptions,
-    );
     distro.addBehavior(
       posixPath.join(rootPathPrefix, '/*/*/*.*'),
       bucketAppsOrigin,
       s3BehaviorOptions,
     );
-    distro.addBehavior(
-      posixPath.join(rootPathPrefix, '/*/*/'),
-      apiGwyOrigin,
-      apiGwyVersionRootBehaviorOptions,
-    );
+
+    //
+    // Everything that isn't a static asset is going to API Gateway
+    // There is no trailing slash because Serverless Next.js wants
+    // go load pages at /release/0.0.3 (with no trailing slash).
+    //
+    distro.addBehavior(posixPath.join(rootPathPrefix, '/*'), apiGwyOrigin, apiGwyBehaviorOptions);
   }
 
   private _cloudFrontDistro: cf.Distribution;


Test patch:
diff --git a/packages/microapps-cdk/test/__snapshots__/MicroAppsCF.test.ts.snap b/packages/microapps-cdk/test/__snapshots__/MicroAppsCF.test.ts.snap
index bba7cd37..8d2a4eb2 100644
--- a/packages/microapps-cdk/test/__snapshots__/MicroAppsCF.test.ts.snap
+++ b/packages/microapps-cdk/test/__snapshots__/MicroAppsCF.test.ts.snap
@@ -33,38 +33,6 @@ Object {
       "Properties": Object {
         "DistributionConfig": Object {
           "CacheBehaviors": Array [
-            Object {
-              "AllowedMethods": Array [
-                "GET",
-                "HEAD",
-                "OPTIONS",
-                "PUT",
-                "PATCH",
-                "POST",
-                "DELETE",
-              ],
-              "CachePolicyId": "4135ea2d-6df8-44a3-9df3-4b5a84be39ad",
-              "Compress": true,
-              "OriginRequestPolicyId": Object {
-                "Ref": "constructapigwyoriginpolicystack77776C6F",
-              },
-              "PathPattern": "/*/*/api/*",
-              "TargetOriginId": "stackconstructcftOrigin1D000029C",
-              "ViewerProtocolPolicy": "redirect-to-https",
-            },
-            Object {
-              "AllowedMethods": Array [
-                "GET",
-                "HEAD",
-                "OPTIONS",
-              ],
-              "CachePolicyId": "658327ea-f89d-4fab-a63d-7e88639e58f6",
-              "Compress": true,
-              "OriginRequestPolicyId": "88a5eaf4-2fd4-4709-b370-b4c650ea3fcf",
-              "PathPattern": "/*/*/static/*",
-              "TargetOriginId": "stackconstructcftOrigin2BE69FFBB",
-              "ViewerProtocolPolicy": "redirect-to-https",
-            },
             Object {
               "AllowedMethods": Array [
                 "GET",
@@ -83,13 +51,17 @@ Object {
                 "GET",
                 "HEAD",
                 "OPTIONS",
+                "PUT",
+                "PATCH",
+                "POST",
+                "DELETE",
               ],
               "CachePolicyId": "4135ea2d-6df8-44a3-9df3-4b5a84be39ad",
               "Compress": true,
               "OriginRequestPolicyId": Object {
                 "Ref": "constructapigwyoriginpolicystack77776C6F",
               },
-              "PathPattern": "/*/*/",
+              "PathPattern": "/*",
               "TargetOriginId": "stackconstructcftOrigin1D000029C",
               "ViewerProtocolPolicy": "redirect-to-https",
             },
@@ -235,36 +207,6 @@ Object {
             "some.test.pwrdrvr.com",
           ],
           "CacheBehaviors": Array [
-            Object {
-              "AllowedMethods": Array [
-                "GET",
-                "HEAD",
-                "OPTIONS",
-                "PUT",
-                "PATCH",
-                "POST",
-                "DELETE",
-              ],
-              "CachePolicyId": "4135ea2d-6df8-44a3-9df3-4b5a84be39ad",
-              "Compress": true,
-              "OriginRequestPolicyId": "216adef6-5c7f-47e4-b989-5492eafa07d3",
-              "PathPattern": "/*/*/api/*",
-              "TargetOriginId": "stackconstructcftOrigin1D000029C",
-              "ViewerProtocolPolicy": "redirect-to-https",
-            },
-            Object {
-              "AllowedMethods": Array [
-                "GET",
-                "HEAD",
-                "OPTIONS",
-              ],
-              "CachePolicyId": "658327ea-f89d-4fab-a63d-7e88639e58f6",
-              "Compress": true,
-              "OriginRequestPolicyId": "88a5eaf4-2fd4-4709-b370-b4c650ea3fcf",
-              "PathPattern": "/*/*/static/*",
-              "TargetOriginId": "stackconstructcftOrigin2BE69FFBB",
-              "ViewerProtocolPolicy": "redirect-to-https",
-            },
             Object {
               "AllowedMethods": Array [
                 "GET",
@@ -283,11 +225,15 @@ Object {
                 "GET",
                 "HEAD",
                 "OPTIONS",
+                "PUT",
+                "PATCH",
+                "POST",
+                "DELETE",
               ],
               "CachePolicyId": "4135ea2d-6df8-44a3-9df3-4b5a84be39ad",
               "Compress": true,
               "OriginRequestPolicyId": "216adef6-5c7f-47e4-b989-5492eafa07d3",
-              "PathPattern": "/*/*/",
+              "PathPattern": "/*",
               "TargetOriginId": "stackconstructcftOrigin1D000029C",
               "ViewerProtocolPolicy": "redirect-to-https",
             },