From 04cb60886539f7bee689714d76d3dad38f5248cb Mon Sep 17 00:00:00 2001 From: Krishan Thisera Date: Wed, 23 Nov 2022 10:05:53 +1030 Subject: [PATCH 01/10] Prerender Handler --- packages/lambda-at-edge-handlers/index.ts | 3 ++ .../lib/prerender-handler.ts | 54 +++++++++++++++++++ packages/lambda-at-edge-handlers/package.json | 24 +++++++++ .../lambda-at-edge-handlers/tsconfig.json | 3 ++ 4 files changed, 84 insertions(+) create mode 100644 packages/lambda-at-edge-handlers/index.ts create mode 100644 packages/lambda-at-edge-handlers/lib/prerender-handler.ts create mode 100644 packages/lambda-at-edge-handlers/package.json create mode 100644 packages/lambda-at-edge-handlers/tsconfig.json diff --git a/packages/lambda-at-edge-handlers/index.ts b/packages/lambda-at-edge-handlers/index.ts new file mode 100644 index 00000000..a2790fd8 --- /dev/null +++ b/packages/lambda-at-edge-handlers/index.ts @@ -0,0 +1,3 @@ +import { prerenderHandler } from "./lib/prerender-handler"; + +export { prerenderHandler }; diff --git a/packages/lambda-at-edge-handlers/lib/prerender-handler.ts b/packages/lambda-at-edge-handlers/lib/prerender-handler.ts new file mode 100644 index 00000000..7e4b069b --- /dev/null +++ b/packages/lambda-at-edge-handlers/lib/prerender-handler.ts @@ -0,0 +1,54 @@ +import "source-map-support/register"; +import { + CloudFrontRequest, + CloudFrontRequestEvent, + CloudFrontResponse, +} from "aws-lambda"; +const PRERENDER_TOKEN = process.env.PRERENDER_TOKEN + ? process.env.PRERENDER_TOKEN + : "undef"; +const PATH_PREFIX = process.env.PATH_PREFIX; +const PRERENDER_URL = process.env.PRERENDER_URL + ? process.env.PRERENDER_URL + : "service.prerender.io"; + +export const prerenderHandler = async ( + event: CloudFrontRequestEvent +): Promise => { + let request = event.Records[0].cf.request; + + // viewer-request function will determine whether we prerender or not + // if we should we add prerender as our custom origin + if (request.headers["x-request-prerender"]) { + // Cloudfront will alter the request for / to /index.html + // since it is defined as the default root object + // we do not want to do this when prerendering the homepage + if (request.uri === `${PATH_PREFIX}/index.html`) { + request.uri = `${PATH_PREFIX}/`; + } + + request.origin = { + custom: { + domainName: PRERENDER_URL, + port: 443, + protocol: "https", + readTimeout: 20, + keepaliveTimeout: 5, + sslProtocols: ["TLSv1", "TLSv1.1", "TLSv1.2"], + path: "/https%3A%2F%2F" + request.headers["x-prerender-host"][0].value, + customHeaders: { + "x-prerender-token": [ + { + key: "x-prerender-token", + value: PRERENDER_TOKEN, + }, + ], + }, + }, + }; + } else { + request.uri = `${PATH_PREFIX}/index.html`; + } + + return request; +}; diff --git a/packages/lambda-at-edge-handlers/package.json b/packages/lambda-at-edge-handlers/package.json new file mode 100644 index 00000000..ff5869b6 --- /dev/null +++ b/packages/lambda-at-edge-handlers/package.json @@ -0,0 +1,24 @@ +{ + "name": "@aligent/lambda-at-edge-handlers", + "version": "0.1.0", + "description": "A Cloudfront Lambda@Edge handlers powered by Middy", + "main": "index.js", + "scripts": { + "build": "tsc && cd ./lib && npm ci", + "prepublish": "tsc && cd ./lib && npm ci" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/aligent/aws-cdk-constructs.git" + }, + "license": "GPL-3.0-only", + "bugs": { + "url": "https://github.com/aligent/cdk-constructs/issues" + }, + "homepage": "https://github.com/aligent/cdk-constructs#readme", + "dependencies": { + "@types/aws-lambda": "^8.10.77", + "esbuild": "0.12.15", + "source-map-support": "^0.5.16" + } +} diff --git a/packages/lambda-at-edge-handlers/tsconfig.json b/packages/lambda-at-edge-handlers/tsconfig.json new file mode 100644 index 00000000..7460ef42 --- /dev/null +++ b/packages/lambda-at-edge-handlers/tsconfig.json @@ -0,0 +1,3 @@ +{ + "extends": "../../tsconfig.json" +} \ No newline at end of file From 29217f8f758bcaed8cdcdac42959520d7c771271 Mon Sep 17 00:00:00 2001 From: Krishan Thisera Date: Wed, 23 Nov 2022 10:06:25 +1030 Subject: [PATCH 02/10] Prerender Handler --- packages/lambda-at-edge-handlers/.gitignore | 58 +++++++++++++++++++++ packages/lambda-at-edge-handlers/.npmignore | 11 ++++ 2 files changed, 69 insertions(+) create mode 100644 packages/lambda-at-edge-handlers/.gitignore create mode 100644 packages/lambda-at-edge-handlers/.npmignore diff --git a/packages/lambda-at-edge-handlers/.gitignore b/packages/lambda-at-edge-handlers/.gitignore new file mode 100644 index 00000000..8f77f768 --- /dev/null +++ b/packages/lambda-at-edge-handlers/.gitignore @@ -0,0 +1,58 @@ +# These are some examples of commonly ignored file patterns. +# You should customize this list as applicable to your project. +# Learn more about .gitignore: +# https://www.atlassian.com/git/tutorials/saving-changes/gitignore + +# Node artifact files +node_modules/ +dist/ + +# Compiled Java class files +*.class + +# Compiled Python bytecode +*.py[cod] + +# Log files +*.log + +# Package files +*.jar + +# Maven +target/ +dist/ + +# JetBrains IDE +.idea/ + +# Unit test reports +TEST*.xml + +# Generated by MacOS +.DS_Store + +# Generated by Windows +Thumbs.db + +# Applications +*.app +*.exe +*.war + +# Large media files +*.mp4 +*.tiff +*.avi +*.flv +*.mov +*.wmv + +!jest.config.js + +# CDK asset staging directory +.cdk.staging +cdk.out + +*.d.ts +*.js diff --git a/packages/lambda-at-edge-handlers/.npmignore b/packages/lambda-at-edge-handlers/.npmignore new file mode 100644 index 00000000..bfd115ba --- /dev/null +++ b/packages/lambda-at-edge-handlers/.npmignore @@ -0,0 +1,11 @@ +*.ts +!lib/handlers/*.ts +!*.d.ts +!*.js + +# CDK asset staging directory +.cdk.staging +cdk.out + +# Samples +sample/ From 7d40209a3236a57587c4b76cef8b93a94d232356 Mon Sep 17 00:00:00 2001 From: Krishan Thisera Date: Wed, 23 Nov 2022 10:16:11 +1030 Subject: [PATCH 03/10] Include the lockfile --- package-lock.json | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/package-lock.json b/package-lock.json index ea05fddb..8cad94c6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -42,6 +42,10 @@ "resolved": "packages/waf", "link": true }, + "node_modules/@aligent/lambda-at-edge-handlers": { + "resolved": "packages/lambda-at-edge-handlers", + "link": true + }, "node_modules/@ampproject/remapping": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/@ampproject/remapping/-/remapping-2.2.0.tgz", @@ -2172,6 +2176,11 @@ "integrity": "sha512-yOlFc+7UtL/89t2ZhjPvvB/DeAr3r+Dq58IgzsFkOAvVC6NMJXmCGjbptdXdR9qsX7pKcTL+s87FtYREi2dEEQ==", "dev": true }, + "node_modules/@types/aws-lambda": { + "version": "8.10.108", + "resolved": "https://registry.npmjs.org/@types/aws-lambda/-/aws-lambda-8.10.108.tgz", + "integrity": "sha512-1yh1W1WoqK3lGHy+V/Fi55zobxrDHUUsluCWdMlOXkCvtsCmHPXOG+CQ2STIL4B1g6xi6I6XzxaF8V9+zeIFLA==" + }, "node_modules/@types/babel__core": { "version": "7.1.20", "resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.1.20.tgz", @@ -7749,6 +7758,15 @@ "integrity": "sha512-J0oqm9ZfAXaPdwNXMMgAhylw5fhmXkToJd06vuDUSAgEDZ/n/69/69UmyBZbc+zT34UnShuDSBqvim3SPnozJg==", "dev": true }, + "packages/lambda-at-edge-handlers": { + "version": "0.1.0", + "license": "GPL-3.0-only", + "dependencies": { + "@types/aws-lambda": "^8.10.77", + "esbuild": "0.12.15", + "source-map-support": "^0.5.16" + } + }, "packages/prerender-proxy": { "name": "@aligent/cdk-prerender-proxy", "version": "0.1.7", @@ -8177,6 +8195,14 @@ } } }, + "@aligent/lambda-at-edge-handlers": { + "version": "file:packages/lambda-at-edge-handlers", + "requires": { + "@types/aws-lambda": "^8.10.77", + "esbuild": "0.12.15", + "source-map-support": "^0.5.16" + } + }, "@ampproject/remapping": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/@ampproject/remapping/-/remapping-2.2.0.tgz", @@ -9600,6 +9626,11 @@ "integrity": "sha512-yOlFc+7UtL/89t2ZhjPvvB/DeAr3r+Dq58IgzsFkOAvVC6NMJXmCGjbptdXdR9qsX7pKcTL+s87FtYREi2dEEQ==", "dev": true }, + "@types/aws-lambda": { + "version": "8.10.108", + "resolved": "https://registry.npmjs.org/@types/aws-lambda/-/aws-lambda-8.10.108.tgz", + "integrity": "sha512-1yh1W1WoqK3lGHy+V/Fi55zobxrDHUUsluCWdMlOXkCvtsCmHPXOG+CQ2STIL4B1g6xi6I6XzxaF8V9+zeIFLA==" + }, "@types/babel__core": { "version": "7.1.20", "resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.1.20.tgz", From 7013a314496727a4d56c271d141d470e49e3aeaf Mon Sep 17 00:00:00 2001 From: Krishan Thisera Date: Wed, 23 Nov 2022 11:36:13 +1030 Subject: [PATCH 04/10] Change package name --- package-lock.json | 25 ++++++++++--------- packages/lambda-at-edge-handlers/package.json | 2 +- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8cad94c6..4bbc512f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -26,6 +26,10 @@ "resolved": "packages/geoip-redirect", "link": true }, + "node_modules/@aligent/cdk-lambda-at-edge-handlers": { + "resolved": "packages/lambda-at-edge-handlers", + "link": true + }, "node_modules/@aligent/cdk-prerender-proxy": { "resolved": "packages/prerender-proxy", "link": true @@ -42,10 +46,6 @@ "resolved": "packages/waf", "link": true }, - "node_modules/@aligent/lambda-at-edge-handlers": { - "resolved": "packages/lambda-at-edge-handlers", - "link": true - }, "node_modules/@ampproject/remapping": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/@ampproject/remapping/-/remapping-2.2.0.tgz", @@ -7759,6 +7759,7 @@ "dev": true }, "packages/lambda-at-edge-handlers": { + "name": "@aligent/cdk-lambda-at-edge-handlers", "version": "0.1.0", "license": "GPL-3.0-only", "dependencies": { @@ -8053,6 +8054,14 @@ } } }, + "@aligent/cdk-lambda-at-edge-handlers": { + "version": "file:packages/lambda-at-edge-handlers", + "requires": { + "@types/aws-lambda": "^8.10.77", + "esbuild": "0.12.15", + "source-map-support": "^0.5.16" + } + }, "@aligent/cdk-prerender-proxy": { "version": "file:packages/prerender-proxy", "requires": { @@ -8195,14 +8204,6 @@ } } }, - "@aligent/lambda-at-edge-handlers": { - "version": "file:packages/lambda-at-edge-handlers", - "requires": { - "@types/aws-lambda": "^8.10.77", - "esbuild": "0.12.15", - "source-map-support": "^0.5.16" - } - }, "@ampproject/remapping": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/@ampproject/remapping/-/remapping-2.2.0.tgz", diff --git a/packages/lambda-at-edge-handlers/package.json b/packages/lambda-at-edge-handlers/package.json index ff5869b6..d91eb17b 100644 --- a/packages/lambda-at-edge-handlers/package.json +++ b/packages/lambda-at-edge-handlers/package.json @@ -1,5 +1,5 @@ { - "name": "@aligent/lambda-at-edge-handlers", + "name": "@aligent/cdk-lambda-at-edge-handlers", "version": "0.1.0", "description": "A Cloudfront Lambda@Edge handlers powered by Middy", "main": "index.js", From 40cccafc58b7ebfdc05243a1974768a51affa201 Mon Sep 17 00:00:00 2001 From: Krishan Thisera Date: Wed, 23 Nov 2022 11:58:21 +1030 Subject: [PATCH 05/10] include jest --- package-lock.json | 70 +++++-------------- packages/lambda-at-edge-handlers/package.json | 1 + 2 files changed, 17 insertions(+), 54 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4bbc512f..08f3730f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2066,7 +2066,6 @@ "version": "26.6.2", "resolved": "https://registry.npmjs.org/@jest/types/-/types-26.6.2.tgz", "integrity": "sha512-fC6QCp7Sc5sX6g8Tvbmj4XUTbyrik0akgRy03yjXbQaBWWNWGE7SGtJk98m0N8nzegD/7SggrUlivxo5ax4KWQ==", - "dev": true, "dependencies": { "@types/istanbul-lib-coverage": "^2.0.0", "@types/istanbul-reports": "^3.0.0", @@ -2234,14 +2233,12 @@ "node_modules/@types/istanbul-lib-coverage": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.4.tgz", - "integrity": "sha512-z/QT1XN4K4KYuslS23k62yDIDLwLFkzxOuMplDtObz0+y7VqJCaO2o+SPwHCvLFZh7xazvvoor2tA/hPz9ee7g==", - "dev": true + "integrity": "sha512-z/QT1XN4K4KYuslS23k62yDIDLwLFkzxOuMplDtObz0+y7VqJCaO2o+SPwHCvLFZh7xazvvoor2tA/hPz9ee7g==" }, "node_modules/@types/istanbul-lib-report": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/@types/istanbul-lib-report/-/istanbul-lib-report-3.0.0.tgz", "integrity": "sha512-plGgXAPfVKFoYfa9NpYDAkseG+g6Jr294RqeqcqDixSbU34MZVJRi/P+7Y8GDpzkEwLaGZZOpKIEmeVZNtKsrg==", - "dev": true, "dependencies": { "@types/istanbul-lib-coverage": "*" } @@ -2250,7 +2247,6 @@ "version": "3.0.1", "resolved": "https://registry.npmjs.org/@types/istanbul-reports/-/istanbul-reports-3.0.1.tgz", "integrity": "sha512-c3mAZEuK0lvBp8tmuL74XRKn1+y2dcwOUpH7x4WrF6gk1GIgiluDRgMYQtw2OFcBvAJWlt6ASU3tSqxp0Uu0Aw==", - "dev": true, "dependencies": { "@types/istanbul-lib-report": "*" } @@ -2259,7 +2255,6 @@ "version": "26.0.24", "resolved": "https://registry.npmjs.org/@types/jest/-/jest-26.0.24.tgz", "integrity": "sha512-E/X5Vib8BWqZNRlDxj9vYXhsDwPYbPINqKF9BsnSoon4RQ0D9moEuLD8txgyypFLH7J4+Lho9Nr/c8H0Fi+17w==", - "dev": true, "dependencies": { "jest-diff": "^26.0.0", "pretty-format": "^26.0.0" @@ -2268,8 +2263,7 @@ "node_modules/@types/node": { "version": "10.17.60", "resolved": "https://registry.npmjs.org/@types/node/-/node-10.17.60.tgz", - "integrity": "sha512-F0KIgDJfy2nA3zMLmWGKxcH2ZVEtCZXHHdOQs2gSaQ27+lNeEfGxzkIw90aXswATX7AZ33tahPbzy6KAfUreVw==", - "dev": true + "integrity": "sha512-F0KIgDJfy2nA3zMLmWGKxcH2ZVEtCZXHHdOQs2gSaQ27+lNeEfGxzkIw90aXswATX7AZ33tahPbzy6KAfUreVw==" }, "node_modules/@types/normalize-package-data": { "version": "2.4.1", @@ -2293,7 +2287,6 @@ "version": "15.0.14", "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-15.0.14.tgz", "integrity": "sha512-yEJzHoxf6SyQGhBhIYGXQDSCkJjB6HohDShto7m8vaKg9Yp0Yn8+71J9eakh2bnPg6BfsH9PRMhiRTZnd4eXGQ==", - "dev": true, "dependencies": { "@types/yargs-parser": "*" } @@ -2301,8 +2294,7 @@ "node_modules/@types/yargs-parser": { "version": "21.0.0", "resolved": "https://registry.npmjs.org/@types/yargs-parser/-/yargs-parser-21.0.0.tgz", - "integrity": "sha512-iO9ZQHkZxHn4mSakYV0vFHAVDyEOIJQrV2uZ06HxEPcx+mt8swXoZHIbaaJ2crJYFfErySgktuTZ3BeLz+XmFA==", - "dev": true + "integrity": "sha512-iO9ZQHkZxHn4mSakYV0vFHAVDyEOIJQrV2uZ06HxEPcx+mt8swXoZHIbaaJ2crJYFfErySgktuTZ3BeLz+XmFA==" }, "node_modules/abab": { "version": "2.0.6", @@ -2400,7 +2392,6 @@ "version": "5.0.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", - "dev": true, "engines": { "node": ">=8" } @@ -2409,7 +2400,6 @@ "version": "4.3.0", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", - "dev": true, "dependencies": { "color-convert": "^2.0.1" }, @@ -2839,7 +2829,6 @@ "version": "4.1.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", - "dev": true, "dependencies": { "ansi-styles": "^4.1.0", "supports-color": "^7.1.0" @@ -3023,7 +3012,6 @@ "version": "2.0.1", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", - "dev": true, "dependencies": { "color-name": "~1.1.4" }, @@ -3034,8 +3022,7 @@ "node_modules/color-name": { "version": "1.1.4", "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", - "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", - "dev": true + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" }, "node_modules/combined-stream": { "version": "1.0.8", @@ -3251,7 +3238,6 @@ "version": "26.6.2", "resolved": "https://registry.npmjs.org/diff-sequences/-/diff-sequences-26.6.2.tgz", "integrity": "sha512-Mv/TDa3nZ9sbc5soK+OoA74BsS3mL37yixCvUAQkiuA4Wz6YtwP/K47n2rv2ovzHZvoiQeA5FTQOschKkEwB0Q==", - "dev": true, "engines": { "node": ">= 10.14.2" } @@ -3892,7 +3878,6 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", - "dev": true, "engines": { "node": ">=8" } @@ -4448,7 +4433,6 @@ "version": "26.6.2", "resolved": "https://registry.npmjs.org/jest-diff/-/jest-diff-26.6.2.tgz", "integrity": "sha512-6m+9Z3Gv9wN0WFVasqjCL/06+EFCMTqDEUl/b87HYK2rAPTyfz4ZIuSlPhY51PIQRWx5TaxeF1qmXKe9gfN3sA==", - "dev": true, "dependencies": { "chalk": "^4.0.0", "diff-sequences": "^26.6.2", @@ -4526,7 +4510,6 @@ "version": "26.3.0", "resolved": "https://registry.npmjs.org/jest-get-type/-/jest-get-type-26.3.0.tgz", "integrity": "sha512-TpfaviN1R2pQWkIihlfEanwOXK0zcxrKEE4MlU6Tn7keoXdN6/3gK/xl0yEh8DOunn5pOVGKf8hB4R9gVh04ig==", - "dev": true, "engines": { "node": ">= 10.14.2" } @@ -5729,7 +5712,6 @@ "version": "26.6.2", "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-26.6.2.tgz", "integrity": "sha512-7AeGuCYNGmycyQbCqd/3PWH4eOoX/OiCa0uphp57NVTeAGdJGaAliecxwBDHYQCIvrW7aDBZCYeNTP/WX69mkg==", - "dev": true, "dependencies": { "@jest/types": "^26.6.2", "ansi-regex": "^5.0.0", @@ -5787,8 +5769,7 @@ "node_modules/react-is": { "version": "17.0.2", "resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz", - "integrity": "sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==", - "dev": true + "integrity": "sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==" }, "node_modules/read-pkg": { "version": "5.2.0", @@ -6886,7 +6867,6 @@ "version": "7.2.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", - "dev": true, "dependencies": { "has-flag": "^4.0.0" }, @@ -7764,6 +7744,7 @@ "license": "GPL-3.0-only", "dependencies": { "@types/aws-lambda": "^8.10.77", + "@types/jest": "^26.0.21", "esbuild": "0.12.15", "source-map-support": "^0.5.16" } @@ -8058,6 +8039,7 @@ "version": "file:packages/lambda-at-edge-handlers", "requires": { "@types/aws-lambda": "^8.10.77", + "@types/jest": "^26.0.21", "esbuild": "0.12.15", "source-map-support": "^0.5.16" } @@ -9532,7 +9514,6 @@ "version": "26.6.2", "resolved": "https://registry.npmjs.org/@jest/types/-/types-26.6.2.tgz", "integrity": "sha512-fC6QCp7Sc5sX6g8Tvbmj4XUTbyrik0akgRy03yjXbQaBWWNWGE7SGtJk98m0N8nzegD/7SggrUlivxo5ax4KWQ==", - "dev": true, "requires": { "@types/istanbul-lib-coverage": "^2.0.0", "@types/istanbul-reports": "^3.0.0", @@ -9685,14 +9666,12 @@ "@types/istanbul-lib-coverage": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.4.tgz", - "integrity": "sha512-z/QT1XN4K4KYuslS23k62yDIDLwLFkzxOuMplDtObz0+y7VqJCaO2o+SPwHCvLFZh7xazvvoor2tA/hPz9ee7g==", - "dev": true + "integrity": "sha512-z/QT1XN4K4KYuslS23k62yDIDLwLFkzxOuMplDtObz0+y7VqJCaO2o+SPwHCvLFZh7xazvvoor2tA/hPz9ee7g==" }, "@types/istanbul-lib-report": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/@types/istanbul-lib-report/-/istanbul-lib-report-3.0.0.tgz", "integrity": "sha512-plGgXAPfVKFoYfa9NpYDAkseG+g6Jr294RqeqcqDixSbU34MZVJRi/P+7Y8GDpzkEwLaGZZOpKIEmeVZNtKsrg==", - "dev": true, "requires": { "@types/istanbul-lib-coverage": "*" } @@ -9701,7 +9680,6 @@ "version": "3.0.1", "resolved": "https://registry.npmjs.org/@types/istanbul-reports/-/istanbul-reports-3.0.1.tgz", "integrity": "sha512-c3mAZEuK0lvBp8tmuL74XRKn1+y2dcwOUpH7x4WrF6gk1GIgiluDRgMYQtw2OFcBvAJWlt6ASU3tSqxp0Uu0Aw==", - "dev": true, "requires": { "@types/istanbul-lib-report": "*" } @@ -9710,7 +9688,6 @@ "version": "26.0.24", "resolved": "https://registry.npmjs.org/@types/jest/-/jest-26.0.24.tgz", "integrity": "sha512-E/X5Vib8BWqZNRlDxj9vYXhsDwPYbPINqKF9BsnSoon4RQ0D9moEuLD8txgyypFLH7J4+Lho9Nr/c8H0Fi+17w==", - "dev": true, "requires": { "jest-diff": "^26.0.0", "pretty-format": "^26.0.0" @@ -9719,8 +9696,7 @@ "@types/node": { "version": "10.17.60", "resolved": "https://registry.npmjs.org/@types/node/-/node-10.17.60.tgz", - "integrity": "sha512-F0KIgDJfy2nA3zMLmWGKxcH2ZVEtCZXHHdOQs2gSaQ27+lNeEfGxzkIw90aXswATX7AZ33tahPbzy6KAfUreVw==", - "dev": true + "integrity": "sha512-F0KIgDJfy2nA3zMLmWGKxcH2ZVEtCZXHHdOQs2gSaQ27+lNeEfGxzkIw90aXswATX7AZ33tahPbzy6KAfUreVw==" }, "@types/normalize-package-data": { "version": "2.4.1", @@ -9744,7 +9720,6 @@ "version": "15.0.14", "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-15.0.14.tgz", "integrity": "sha512-yEJzHoxf6SyQGhBhIYGXQDSCkJjB6HohDShto7m8vaKg9Yp0Yn8+71J9eakh2bnPg6BfsH9PRMhiRTZnd4eXGQ==", - "dev": true, "requires": { "@types/yargs-parser": "*" } @@ -9752,8 +9727,7 @@ "@types/yargs-parser": { "version": "21.0.0", "resolved": "https://registry.npmjs.org/@types/yargs-parser/-/yargs-parser-21.0.0.tgz", - "integrity": "sha512-iO9ZQHkZxHn4mSakYV0vFHAVDyEOIJQrV2uZ06HxEPcx+mt8swXoZHIbaaJ2crJYFfErySgktuTZ3BeLz+XmFA==", - "dev": true + "integrity": "sha512-iO9ZQHkZxHn4mSakYV0vFHAVDyEOIJQrV2uZ06HxEPcx+mt8swXoZHIbaaJ2crJYFfErySgktuTZ3BeLz+XmFA==" }, "abab": { "version": "2.0.6", @@ -9824,14 +9798,12 @@ "ansi-regex": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", - "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", - "dev": true + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==" }, "ansi-styles": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", - "dev": true, "requires": { "color-convert": "^2.0.1" } @@ -10149,7 +10121,6 @@ "version": "4.1.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", - "dev": true, "requires": { "ansi-styles": "^4.1.0", "supports-color": "^7.1.0" @@ -10296,7 +10267,6 @@ "version": "2.0.1", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", - "dev": true, "requires": { "color-name": "~1.1.4" } @@ -10304,8 +10274,7 @@ "color-name": { "version": "1.1.4", "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", - "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", - "dev": true + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" }, "combined-stream": { "version": "1.0.8", @@ -10472,8 +10441,7 @@ "diff-sequences": { "version": "26.6.2", "resolved": "https://registry.npmjs.org/diff-sequences/-/diff-sequences-26.6.2.tgz", - "integrity": "sha512-Mv/TDa3nZ9sbc5soK+OoA74BsS3mL37yixCvUAQkiuA4Wz6YtwP/K47n2rv2ovzHZvoiQeA5FTQOschKkEwB0Q==", - "dev": true + "integrity": "sha512-Mv/TDa3nZ9sbc5soK+OoA74BsS3mL37yixCvUAQkiuA4Wz6YtwP/K47n2rv2ovzHZvoiQeA5FTQOschKkEwB0Q==" }, "domexception": { "version": "2.0.1", @@ -10964,8 +10932,7 @@ "has-flag": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", - "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", - "dev": true + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==" }, "has-value": { "version": "1.0.0", @@ -11385,7 +11352,6 @@ "version": "26.6.2", "resolved": "https://registry.npmjs.org/jest-diff/-/jest-diff-26.6.2.tgz", "integrity": "sha512-6m+9Z3Gv9wN0WFVasqjCL/06+EFCMTqDEUl/b87HYK2rAPTyfz4ZIuSlPhY51PIQRWx5TaxeF1qmXKe9gfN3sA==", - "dev": true, "requires": { "chalk": "^4.0.0", "diff-sequences": "^26.6.2", @@ -11447,8 +11413,7 @@ "jest-get-type": { "version": "26.3.0", "resolved": "https://registry.npmjs.org/jest-get-type/-/jest-get-type-26.3.0.tgz", - "integrity": "sha512-TpfaviN1R2pQWkIihlfEanwOXK0zcxrKEE4MlU6Tn7keoXdN6/3gK/xl0yEh8DOunn5pOVGKf8hB4R9gVh04ig==", - "dev": true + "integrity": "sha512-TpfaviN1R2pQWkIihlfEanwOXK0zcxrKEE4MlU6Tn7keoXdN6/3gK/xl0yEh8DOunn5pOVGKf8hB4R9gVh04ig==" }, "jest-haste-map": { "version": "26.6.2", @@ -12386,7 +12351,6 @@ "version": "26.6.2", "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-26.6.2.tgz", "integrity": "sha512-7AeGuCYNGmycyQbCqd/3PWH4eOoX/OiCa0uphp57NVTeAGdJGaAliecxwBDHYQCIvrW7aDBZCYeNTP/WX69mkg==", - "dev": true, "requires": { "@jest/types": "^26.6.2", "ansi-regex": "^5.0.0", @@ -12435,8 +12399,7 @@ "react-is": { "version": "17.0.2", "resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz", - "integrity": "sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==", - "dev": true + "integrity": "sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==" }, "read-pkg": { "version": "5.2.0", @@ -13314,7 +13277,6 @@ "version": "7.2.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", - "dev": true, "requires": { "has-flag": "^4.0.0" } diff --git a/packages/lambda-at-edge-handlers/package.json b/packages/lambda-at-edge-handlers/package.json index d91eb17b..b23e8698 100644 --- a/packages/lambda-at-edge-handlers/package.json +++ b/packages/lambda-at-edge-handlers/package.json @@ -19,6 +19,7 @@ "dependencies": { "@types/aws-lambda": "^8.10.77", "esbuild": "0.12.15", + "@types/jest": "^26.0.21", "source-map-support": "^0.5.16" } } From 1d68b07b752a1a6fac7d650c17a377a5730d7529 Mon Sep 17 00:00:00 2001 From: Krishan Thisera Date: Wed, 23 Nov 2022 14:41:46 +1030 Subject: [PATCH 06/10] fixed npm build issues --- package-lock.json | 70 +++++++++++---- .../lambda-at-edge-handlers/package-lock.json | 85 +++++++++++++++++++ packages/lambda-at-edge-handlers/package.json | 7 +- 3 files changed, 143 insertions(+), 19 deletions(-) create mode 100644 packages/lambda-at-edge-handlers/package-lock.json diff --git a/package-lock.json b/package-lock.json index 08f3730f..4bbc512f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2066,6 +2066,7 @@ "version": "26.6.2", "resolved": "https://registry.npmjs.org/@jest/types/-/types-26.6.2.tgz", "integrity": "sha512-fC6QCp7Sc5sX6g8Tvbmj4XUTbyrik0akgRy03yjXbQaBWWNWGE7SGtJk98m0N8nzegD/7SggrUlivxo5ax4KWQ==", + "dev": true, "dependencies": { "@types/istanbul-lib-coverage": "^2.0.0", "@types/istanbul-reports": "^3.0.0", @@ -2233,12 +2234,14 @@ "node_modules/@types/istanbul-lib-coverage": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.4.tgz", - "integrity": "sha512-z/QT1XN4K4KYuslS23k62yDIDLwLFkzxOuMplDtObz0+y7VqJCaO2o+SPwHCvLFZh7xazvvoor2tA/hPz9ee7g==" + "integrity": "sha512-z/QT1XN4K4KYuslS23k62yDIDLwLFkzxOuMplDtObz0+y7VqJCaO2o+SPwHCvLFZh7xazvvoor2tA/hPz9ee7g==", + "dev": true }, "node_modules/@types/istanbul-lib-report": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/@types/istanbul-lib-report/-/istanbul-lib-report-3.0.0.tgz", "integrity": "sha512-plGgXAPfVKFoYfa9NpYDAkseG+g6Jr294RqeqcqDixSbU34MZVJRi/P+7Y8GDpzkEwLaGZZOpKIEmeVZNtKsrg==", + "dev": true, "dependencies": { "@types/istanbul-lib-coverage": "*" } @@ -2247,6 +2250,7 @@ "version": "3.0.1", "resolved": "https://registry.npmjs.org/@types/istanbul-reports/-/istanbul-reports-3.0.1.tgz", "integrity": "sha512-c3mAZEuK0lvBp8tmuL74XRKn1+y2dcwOUpH7x4WrF6gk1GIgiluDRgMYQtw2OFcBvAJWlt6ASU3tSqxp0Uu0Aw==", + "dev": true, "dependencies": { "@types/istanbul-lib-report": "*" } @@ -2255,6 +2259,7 @@ "version": "26.0.24", "resolved": "https://registry.npmjs.org/@types/jest/-/jest-26.0.24.tgz", "integrity": "sha512-E/X5Vib8BWqZNRlDxj9vYXhsDwPYbPINqKF9BsnSoon4RQ0D9moEuLD8txgyypFLH7J4+Lho9Nr/c8H0Fi+17w==", + "dev": true, "dependencies": { "jest-diff": "^26.0.0", "pretty-format": "^26.0.0" @@ -2263,7 +2268,8 @@ "node_modules/@types/node": { "version": "10.17.60", "resolved": "https://registry.npmjs.org/@types/node/-/node-10.17.60.tgz", - "integrity": "sha512-F0KIgDJfy2nA3zMLmWGKxcH2ZVEtCZXHHdOQs2gSaQ27+lNeEfGxzkIw90aXswATX7AZ33tahPbzy6KAfUreVw==" + "integrity": "sha512-F0KIgDJfy2nA3zMLmWGKxcH2ZVEtCZXHHdOQs2gSaQ27+lNeEfGxzkIw90aXswATX7AZ33tahPbzy6KAfUreVw==", + "dev": true }, "node_modules/@types/normalize-package-data": { "version": "2.4.1", @@ -2287,6 +2293,7 @@ "version": "15.0.14", "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-15.0.14.tgz", "integrity": "sha512-yEJzHoxf6SyQGhBhIYGXQDSCkJjB6HohDShto7m8vaKg9Yp0Yn8+71J9eakh2bnPg6BfsH9PRMhiRTZnd4eXGQ==", + "dev": true, "dependencies": { "@types/yargs-parser": "*" } @@ -2294,7 +2301,8 @@ "node_modules/@types/yargs-parser": { "version": "21.0.0", "resolved": "https://registry.npmjs.org/@types/yargs-parser/-/yargs-parser-21.0.0.tgz", - "integrity": "sha512-iO9ZQHkZxHn4mSakYV0vFHAVDyEOIJQrV2uZ06HxEPcx+mt8swXoZHIbaaJ2crJYFfErySgktuTZ3BeLz+XmFA==" + "integrity": "sha512-iO9ZQHkZxHn4mSakYV0vFHAVDyEOIJQrV2uZ06HxEPcx+mt8swXoZHIbaaJ2crJYFfErySgktuTZ3BeLz+XmFA==", + "dev": true }, "node_modules/abab": { "version": "2.0.6", @@ -2392,6 +2400,7 @@ "version": "5.0.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "dev": true, "engines": { "node": ">=8" } @@ -2400,6 +2409,7 @@ "version": "4.3.0", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "dev": true, "dependencies": { "color-convert": "^2.0.1" }, @@ -2829,6 +2839,7 @@ "version": "4.1.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, "dependencies": { "ansi-styles": "^4.1.0", "supports-color": "^7.1.0" @@ -3012,6 +3023,7 @@ "version": "2.0.1", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dev": true, "dependencies": { "color-name": "~1.1.4" }, @@ -3022,7 +3034,8 @@ "node_modules/color-name": { "version": "1.1.4", "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", - "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "dev": true }, "node_modules/combined-stream": { "version": "1.0.8", @@ -3238,6 +3251,7 @@ "version": "26.6.2", "resolved": "https://registry.npmjs.org/diff-sequences/-/diff-sequences-26.6.2.tgz", "integrity": "sha512-Mv/TDa3nZ9sbc5soK+OoA74BsS3mL37yixCvUAQkiuA4Wz6YtwP/K47n2rv2ovzHZvoiQeA5FTQOschKkEwB0Q==", + "dev": true, "engines": { "node": ">= 10.14.2" } @@ -3878,6 +3892,7 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "dev": true, "engines": { "node": ">=8" } @@ -4433,6 +4448,7 @@ "version": "26.6.2", "resolved": "https://registry.npmjs.org/jest-diff/-/jest-diff-26.6.2.tgz", "integrity": "sha512-6m+9Z3Gv9wN0WFVasqjCL/06+EFCMTqDEUl/b87HYK2rAPTyfz4ZIuSlPhY51PIQRWx5TaxeF1qmXKe9gfN3sA==", + "dev": true, "dependencies": { "chalk": "^4.0.0", "diff-sequences": "^26.6.2", @@ -4510,6 +4526,7 @@ "version": "26.3.0", "resolved": "https://registry.npmjs.org/jest-get-type/-/jest-get-type-26.3.0.tgz", "integrity": "sha512-TpfaviN1R2pQWkIihlfEanwOXK0zcxrKEE4MlU6Tn7keoXdN6/3gK/xl0yEh8DOunn5pOVGKf8hB4R9gVh04ig==", + "dev": true, "engines": { "node": ">= 10.14.2" } @@ -5712,6 +5729,7 @@ "version": "26.6.2", "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-26.6.2.tgz", "integrity": "sha512-7AeGuCYNGmycyQbCqd/3PWH4eOoX/OiCa0uphp57NVTeAGdJGaAliecxwBDHYQCIvrW7aDBZCYeNTP/WX69mkg==", + "dev": true, "dependencies": { "@jest/types": "^26.6.2", "ansi-regex": "^5.0.0", @@ -5769,7 +5787,8 @@ "node_modules/react-is": { "version": "17.0.2", "resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz", - "integrity": "sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==" + "integrity": "sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==", + "dev": true }, "node_modules/read-pkg": { "version": "5.2.0", @@ -6867,6 +6886,7 @@ "version": "7.2.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "dev": true, "dependencies": { "has-flag": "^4.0.0" }, @@ -7744,7 +7764,6 @@ "license": "GPL-3.0-only", "dependencies": { "@types/aws-lambda": "^8.10.77", - "@types/jest": "^26.0.21", "esbuild": "0.12.15", "source-map-support": "^0.5.16" } @@ -8039,7 +8058,6 @@ "version": "file:packages/lambda-at-edge-handlers", "requires": { "@types/aws-lambda": "^8.10.77", - "@types/jest": "^26.0.21", "esbuild": "0.12.15", "source-map-support": "^0.5.16" } @@ -9514,6 +9532,7 @@ "version": "26.6.2", "resolved": "https://registry.npmjs.org/@jest/types/-/types-26.6.2.tgz", "integrity": "sha512-fC6QCp7Sc5sX6g8Tvbmj4XUTbyrik0akgRy03yjXbQaBWWNWGE7SGtJk98m0N8nzegD/7SggrUlivxo5ax4KWQ==", + "dev": true, "requires": { "@types/istanbul-lib-coverage": "^2.0.0", "@types/istanbul-reports": "^3.0.0", @@ -9666,12 +9685,14 @@ "@types/istanbul-lib-coverage": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.4.tgz", - "integrity": "sha512-z/QT1XN4K4KYuslS23k62yDIDLwLFkzxOuMplDtObz0+y7VqJCaO2o+SPwHCvLFZh7xazvvoor2tA/hPz9ee7g==" + "integrity": "sha512-z/QT1XN4K4KYuslS23k62yDIDLwLFkzxOuMplDtObz0+y7VqJCaO2o+SPwHCvLFZh7xazvvoor2tA/hPz9ee7g==", + "dev": true }, "@types/istanbul-lib-report": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/@types/istanbul-lib-report/-/istanbul-lib-report-3.0.0.tgz", "integrity": "sha512-plGgXAPfVKFoYfa9NpYDAkseG+g6Jr294RqeqcqDixSbU34MZVJRi/P+7Y8GDpzkEwLaGZZOpKIEmeVZNtKsrg==", + "dev": true, "requires": { "@types/istanbul-lib-coverage": "*" } @@ -9680,6 +9701,7 @@ "version": "3.0.1", "resolved": "https://registry.npmjs.org/@types/istanbul-reports/-/istanbul-reports-3.0.1.tgz", "integrity": "sha512-c3mAZEuK0lvBp8tmuL74XRKn1+y2dcwOUpH7x4WrF6gk1GIgiluDRgMYQtw2OFcBvAJWlt6ASU3tSqxp0Uu0Aw==", + "dev": true, "requires": { "@types/istanbul-lib-report": "*" } @@ -9688,6 +9710,7 @@ "version": "26.0.24", "resolved": "https://registry.npmjs.org/@types/jest/-/jest-26.0.24.tgz", "integrity": "sha512-E/X5Vib8BWqZNRlDxj9vYXhsDwPYbPINqKF9BsnSoon4RQ0D9moEuLD8txgyypFLH7J4+Lho9Nr/c8H0Fi+17w==", + "dev": true, "requires": { "jest-diff": "^26.0.0", "pretty-format": "^26.0.0" @@ -9696,7 +9719,8 @@ "@types/node": { "version": "10.17.60", "resolved": "https://registry.npmjs.org/@types/node/-/node-10.17.60.tgz", - "integrity": "sha512-F0KIgDJfy2nA3zMLmWGKxcH2ZVEtCZXHHdOQs2gSaQ27+lNeEfGxzkIw90aXswATX7AZ33tahPbzy6KAfUreVw==" + "integrity": "sha512-F0KIgDJfy2nA3zMLmWGKxcH2ZVEtCZXHHdOQs2gSaQ27+lNeEfGxzkIw90aXswATX7AZ33tahPbzy6KAfUreVw==", + "dev": true }, "@types/normalize-package-data": { "version": "2.4.1", @@ -9720,6 +9744,7 @@ "version": "15.0.14", "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-15.0.14.tgz", "integrity": "sha512-yEJzHoxf6SyQGhBhIYGXQDSCkJjB6HohDShto7m8vaKg9Yp0Yn8+71J9eakh2bnPg6BfsH9PRMhiRTZnd4eXGQ==", + "dev": true, "requires": { "@types/yargs-parser": "*" } @@ -9727,7 +9752,8 @@ "@types/yargs-parser": { "version": "21.0.0", "resolved": "https://registry.npmjs.org/@types/yargs-parser/-/yargs-parser-21.0.0.tgz", - "integrity": "sha512-iO9ZQHkZxHn4mSakYV0vFHAVDyEOIJQrV2uZ06HxEPcx+mt8swXoZHIbaaJ2crJYFfErySgktuTZ3BeLz+XmFA==" + "integrity": "sha512-iO9ZQHkZxHn4mSakYV0vFHAVDyEOIJQrV2uZ06HxEPcx+mt8swXoZHIbaaJ2crJYFfErySgktuTZ3BeLz+XmFA==", + "dev": true }, "abab": { "version": "2.0.6", @@ -9798,12 +9824,14 @@ "ansi-regex": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", - "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==" + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "dev": true }, "ansi-styles": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "dev": true, "requires": { "color-convert": "^2.0.1" } @@ -10121,6 +10149,7 @@ "version": "4.1.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, "requires": { "ansi-styles": "^4.1.0", "supports-color": "^7.1.0" @@ -10267,6 +10296,7 @@ "version": "2.0.1", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dev": true, "requires": { "color-name": "~1.1.4" } @@ -10274,7 +10304,8 @@ "color-name": { "version": "1.1.4", "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", - "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "dev": true }, "combined-stream": { "version": "1.0.8", @@ -10441,7 +10472,8 @@ "diff-sequences": { "version": "26.6.2", "resolved": "https://registry.npmjs.org/diff-sequences/-/diff-sequences-26.6.2.tgz", - "integrity": "sha512-Mv/TDa3nZ9sbc5soK+OoA74BsS3mL37yixCvUAQkiuA4Wz6YtwP/K47n2rv2ovzHZvoiQeA5FTQOschKkEwB0Q==" + "integrity": "sha512-Mv/TDa3nZ9sbc5soK+OoA74BsS3mL37yixCvUAQkiuA4Wz6YtwP/K47n2rv2ovzHZvoiQeA5FTQOschKkEwB0Q==", + "dev": true }, "domexception": { "version": "2.0.1", @@ -10932,7 +10964,8 @@ "has-flag": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", - "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==" + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "dev": true }, "has-value": { "version": "1.0.0", @@ -11352,6 +11385,7 @@ "version": "26.6.2", "resolved": "https://registry.npmjs.org/jest-diff/-/jest-diff-26.6.2.tgz", "integrity": "sha512-6m+9Z3Gv9wN0WFVasqjCL/06+EFCMTqDEUl/b87HYK2rAPTyfz4ZIuSlPhY51PIQRWx5TaxeF1qmXKe9gfN3sA==", + "dev": true, "requires": { "chalk": "^4.0.0", "diff-sequences": "^26.6.2", @@ -11413,7 +11447,8 @@ "jest-get-type": { "version": "26.3.0", "resolved": "https://registry.npmjs.org/jest-get-type/-/jest-get-type-26.3.0.tgz", - "integrity": "sha512-TpfaviN1R2pQWkIihlfEanwOXK0zcxrKEE4MlU6Tn7keoXdN6/3gK/xl0yEh8DOunn5pOVGKf8hB4R9gVh04ig==" + "integrity": "sha512-TpfaviN1R2pQWkIihlfEanwOXK0zcxrKEE4MlU6Tn7keoXdN6/3gK/xl0yEh8DOunn5pOVGKf8hB4R9gVh04ig==", + "dev": true }, "jest-haste-map": { "version": "26.6.2", @@ -12351,6 +12386,7 @@ "version": "26.6.2", "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-26.6.2.tgz", "integrity": "sha512-7AeGuCYNGmycyQbCqd/3PWH4eOoX/OiCa0uphp57NVTeAGdJGaAliecxwBDHYQCIvrW7aDBZCYeNTP/WX69mkg==", + "dev": true, "requires": { "@jest/types": "^26.6.2", "ansi-regex": "^5.0.0", @@ -12399,7 +12435,8 @@ "react-is": { "version": "17.0.2", "resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz", - "integrity": "sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==" + "integrity": "sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==", + "dev": true }, "read-pkg": { "version": "5.2.0", @@ -13277,6 +13314,7 @@ "version": "7.2.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "dev": true, "requires": { "has-flag": "^4.0.0" } diff --git a/packages/lambda-at-edge-handlers/package-lock.json b/packages/lambda-at-edge-handlers/package-lock.json new file mode 100644 index 00000000..3ab5d49f --- /dev/null +++ b/packages/lambda-at-edge-handlers/package-lock.json @@ -0,0 +1,85 @@ +{ + "name": "@aligent/cdk-lambda-at-edge-handlers", + "version": "0.1.0", + "lockfileVersion": 2, + "requires": true, + "packages": { + "": { + "name": "@aligent/cdk-lambda-at-edge-handlers", + "version": "0.1.0", + "license": "GPL-3.0-only", + "dependencies": { + "@types/aws-lambda": "^8.10.77", + "esbuild": "0.12.15", + "source-map-support": "^0.5.16" + } + }, + "node_modules/@types/aws-lambda": { + "version": "8.10.108", + "resolved": "https://registry.npmjs.org/@types/aws-lambda/-/aws-lambda-8.10.108.tgz", + "integrity": "sha512-1yh1W1WoqK3lGHy+V/Fi55zobxrDHUUsluCWdMlOXkCvtsCmHPXOG+CQ2STIL4B1g6xi6I6XzxaF8V9+zeIFLA==" + }, + "node_modules/buffer-from": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz", + "integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==" + }, + "node_modules/esbuild": { + "version": "0.12.15", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.12.15.tgz", + "integrity": "sha512-72V4JNd2+48eOVCXx49xoSWHgC3/cCy96e7mbXKY+WOWghN00cCmlGnwVLRhRHorvv0dgCyuMYBZlM2xDM5OQw==", + "hasInstallScript": true, + "bin": { + "esbuild": "bin/esbuild" + } + }, + "node_modules/source-map": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/source-map-support": { + "version": "0.5.21", + "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.21.tgz", + "integrity": "sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==", + "dependencies": { + "buffer-from": "^1.0.0", + "source-map": "^0.6.0" + } + } + }, + "dependencies": { + "@types/aws-lambda": { + "version": "8.10.108", + "resolved": "https://registry.npmjs.org/@types/aws-lambda/-/aws-lambda-8.10.108.tgz", + "integrity": "sha512-1yh1W1WoqK3lGHy+V/Fi55zobxrDHUUsluCWdMlOXkCvtsCmHPXOG+CQ2STIL4B1g6xi6I6XzxaF8V9+zeIFLA==" + }, + "buffer-from": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz", + "integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==" + }, + "esbuild": { + "version": "0.12.15", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.12.15.tgz", + "integrity": "sha512-72V4JNd2+48eOVCXx49xoSWHgC3/cCy96e7mbXKY+WOWghN00cCmlGnwVLRhRHorvv0dgCyuMYBZlM2xDM5OQw==" + }, + "source-map": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==" + }, + "source-map-support": { + "version": "0.5.21", + "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.21.tgz", + "integrity": "sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==", + "requires": { + "buffer-from": "^1.0.0", + "source-map": "^0.6.0" + } + } + } +} diff --git a/packages/lambda-at-edge-handlers/package.json b/packages/lambda-at-edge-handlers/package.json index b23e8698..21249d31 100644 --- a/packages/lambda-at-edge-handlers/package.json +++ b/packages/lambda-at-edge-handlers/package.json @@ -4,8 +4,10 @@ "description": "A Cloudfront Lambda@Edge handlers powered by Middy", "main": "index.js", "scripts": { - "build": "tsc && cd ./lib && npm ci", - "prepublish": "tsc && cd ./lib && npm ci" + "build": "tsc", + "prepublish": "tsc", + "watch": "tsc -w", + "test": "No test specified\" && exit 0" }, "repository": { "type": "git", @@ -19,7 +21,6 @@ "dependencies": { "@types/aws-lambda": "^8.10.77", "esbuild": "0.12.15", - "@types/jest": "^26.0.21", "source-map-support": "^0.5.16" } } From 1c777bc17eda183466c5d02b7808437937538620 Mon Sep 17 00:00:00 2001 From: Krishan Thisera Date: Wed, 23 Nov 2022 14:45:39 +1030 Subject: [PATCH 07/10] fixed npm package test issue --- packages/lambda-at-edge-handlers/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/lambda-at-edge-handlers/package.json b/packages/lambda-at-edge-handlers/package.json index 21249d31..250092e4 100644 --- a/packages/lambda-at-edge-handlers/package.json +++ b/packages/lambda-at-edge-handlers/package.json @@ -7,7 +7,7 @@ "build": "tsc", "prepublish": "tsc", "watch": "tsc -w", - "test": "No test specified\" && exit 0" + "test": "echo \"No test specified\" && exit 0" }, "repository": { "type": "git", From ed19a4800f6557c8fa8e4eca5f7d93b2b4275113 Mon Sep 17 00:00:00 2001 From: Krishan Thisera Date: Tue, 29 Nov 2022 10:53:40 +1030 Subject: [PATCH 08/10] DO-1410: Lambda at edge handler lib --- packages/lambda-at-edge-handlers/.gitignore | 2 +- packages/lambda-at-edge-handlers/index.ts | 14 ++++- .../lib/cache-control.ts | 21 +++++++ .../lib/error-response.ts | 61 +++++++++++++++++++ .../lib/prerender-check.ts | 35 +++++++++++ .../{prerender-handler.ts => prerender.ts} | 5 +- .../lambda-at-edge-handlers/lib/redirect.ts | 34 +++++++++++ .../lambda-at-edge-handlers/package-lock.json | 12 ++-- packages/lambda-at-edge-handlers/package.json | 3 +- 9 files changed, 175 insertions(+), 12 deletions(-) create mode 100644 packages/lambda-at-edge-handlers/lib/cache-control.ts create mode 100644 packages/lambda-at-edge-handlers/lib/error-response.ts create mode 100644 packages/lambda-at-edge-handlers/lib/prerender-check.ts rename packages/lambda-at-edge-handlers/lib/{prerender-handler.ts => prerender.ts} (96%) create mode 100644 packages/lambda-at-edge-handlers/lib/redirect.ts diff --git a/packages/lambda-at-edge-handlers/.gitignore b/packages/lambda-at-edge-handlers/.gitignore index 8f77f768..75ecda95 100644 --- a/packages/lambda-at-edge-handlers/.gitignore +++ b/packages/lambda-at-edge-handlers/.gitignore @@ -55,4 +55,4 @@ Thumbs.db cdk.out *.d.ts -*.js +*.js \ No newline at end of file diff --git a/packages/lambda-at-edge-handlers/index.ts b/packages/lambda-at-edge-handlers/index.ts index a2790fd8..3bade8fe 100644 --- a/packages/lambda-at-edge-handlers/index.ts +++ b/packages/lambda-at-edge-handlers/index.ts @@ -1,3 +1,13 @@ -import { prerenderHandler } from "./lib/prerender-handler"; +import { handler as PrerenderHandler } from "./lib/prerender"; +import { handler as PrerenderCacheControlHandler } from "./lib/cache-control"; +import { handler as PrerenderErrorResponseHandler } from "./lib/error-response"; +import { handler as PrerenderCheckHandler } from "./lib/prerender-check"; +import { handler as GeoIpRedirectHandler } from "./lib/redirect"; -export { prerenderHandler }; +export { + PrerenderHandler, + PrerenderCacheControlHandler, + PrerenderErrorResponseHandler, + PrerenderCheckHandler, + GeoIpRedirectHandler, +}; diff --git a/packages/lambda-at-edge-handlers/lib/cache-control.ts b/packages/lambda-at-edge-handlers/lib/cache-control.ts new file mode 100644 index 00000000..cb15455f --- /dev/null +++ b/packages/lambda-at-edge-handlers/lib/cache-control.ts @@ -0,0 +1,21 @@ +import 'source-map-support/register'; +import { CloudFrontResponseEvent, CloudFrontResponse } from 'aws-lambda'; +/* + Prerender cache control function + Consider associate this function as *origin response* function +*/ +export const handler = async (event: CloudFrontResponseEvent): Promise => { + const cacheKey = process.env.PRERENDER_CACHE_KEY || 'x-prerender-requestid'; + const cacheMaxAge = process.env.PRERENDER_CACHE_MAX_AGE || '0'; + let response = event.Records[0].cf.response; + + if (response.headers[`${cacheKey}`]) { + response.headers['Cache-Control'] = [ + { + key: 'Cache-Control', + value: `max-age=${cacheMaxAge}` + } + ] + } + return response; +} diff --git a/packages/lambda-at-edge-handlers/lib/error-response.ts b/packages/lambda-at-edge-handlers/lib/error-response.ts new file mode 100644 index 00000000..c4e44903 --- /dev/null +++ b/packages/lambda-at-edge-handlers/lib/error-response.ts @@ -0,0 +1,61 @@ +import "source-map-support/register"; +import { + CloudFrontRequest, + CloudFrontResponseEvent, + CloudFrontResponse, +} from "aws-lambda"; +import axios from "axios"; +import * as https from "https"; + +const FRONTEND_HOST = process.env.FRONTEND_HOST; +const PATH_PREFIX = process.env.PATH_PREFIX; + +// Create axios client outside of lambda function for re-use between calls +const instance = axios.create({ + timeout: 1000, + // Don't follow redirects + maxRedirects: 0, + // Only valid response codes are 200 + validateStatus: function (status) { + return status == 200; + }, + // keep connection alive so we don't constantly do SSL negotiation + httpsAgent: new https.Agent({ keepAlive: true }), +}); + +export const handler = ( + event: CloudFrontResponseEvent +): Promise => { + let response = event.Records[0].cf.response; + let request = event.Records[0].cf.request; + + if ( + response.status != "200" && + !request.headers["x-request-prerender"] && + request.uri != `${PATH_PREFIX}/index.html` + ) { + // Fetch default page and return body + return instance + .get(`https://${FRONTEND_HOST}${PATH_PREFIX}/index.html`) + .then((res) => { + response.body = res.data; + + response.headers["content-type"] = [ + { + key: "Content-Type", + value: "text/html", + }, + ]; + + // Remove content-length if set as this may be the value from the origin. + delete response.headers["content-length"]; + + return response; + }) + .catch((err) => { + return response; + }); + } + + return Promise.resolve(response); +}; diff --git a/packages/lambda-at-edge-handlers/lib/prerender-check.ts b/packages/lambda-at-edge-handlers/lib/prerender-check.ts new file mode 100644 index 00000000..6b4ec090 --- /dev/null +++ b/packages/lambda-at-edge-handlers/lib/prerender-check.ts @@ -0,0 +1,35 @@ +import "source-map-support/register"; +import { CloudFrontRequest, CloudFrontRequestEvent } from "aws-lambda"; + +const IS_BOT = + /googlebot|chrome-lighthouse|lighthouse|adsbot\-google|Feedfetcher\-Google|bingbot|yandex|baiduspider|Facebot|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|quora link preview|showyoubot|outbrain|pinterest|slackbot|vkShare|W3C_Validator/i; +const IS_FILE = + /\.(js|css|xml|less|png|jpg|jpeg|gif|pdf|doc|txt|ico|rss|zip|mp3|rar|exe|wmv|doc|avi|ppt|mpg|mpeg|tif|wav|mov|psd|ai|xls|mp4|m4a|swf|dat|dmg|iso|flv|m4v|torrent|ttf|woff|svg|eot)$/i; + +export const handler = async ( + event: CloudFrontRequestEvent +): Promise => { + let request = event.Records[0].cf.request; + + // If the request is from a bot, is not a file and is not from prerender + // then set the x-request-prerender header so the origin-request lambda function + // alters the origin to prerender.io + if ( + !IS_FILE.test(request.uri) && + IS_BOT.test(request.headers["user-agent"][0].value) && + !request.headers["x-prerender"] + ) { + request.headers["x-request-prerender"] = [ + { + key: "x-request-prerender", + value: "true", + }, + ]; + + request.headers["x-prerender-host"] = [ + { key: "X-Prerender-Host", value: request.headers.host[0].value }, + ]; + } + + return request; +}; diff --git a/packages/lambda-at-edge-handlers/lib/prerender-handler.ts b/packages/lambda-at-edge-handlers/lib/prerender.ts similarity index 96% rename from packages/lambda-at-edge-handlers/lib/prerender-handler.ts rename to packages/lambda-at-edge-handlers/lib/prerender.ts index 7e4b069b..d898fa06 100644 --- a/packages/lambda-at-edge-handlers/lib/prerender-handler.ts +++ b/packages/lambda-at-edge-handlers/lib/prerender.ts @@ -4,15 +4,16 @@ import { CloudFrontRequestEvent, CloudFrontResponse, } from "aws-lambda"; + const PRERENDER_TOKEN = process.env.PRERENDER_TOKEN ? process.env.PRERENDER_TOKEN - : "undef"; + : "undefined"; const PATH_PREFIX = process.env.PATH_PREFIX; const PRERENDER_URL = process.env.PRERENDER_URL ? process.env.PRERENDER_URL : "service.prerender.io"; -export const prerenderHandler = async ( +export const handler = async ( event: CloudFrontRequestEvent ): Promise => { let request = event.Records[0].cf.request; diff --git a/packages/lambda-at-edge-handlers/lib/redirect.ts b/packages/lambda-at-edge-handlers/lib/redirect.ts new file mode 100644 index 00000000..fe260ccc --- /dev/null +++ b/packages/lambda-at-edge-handlers/lib/redirect.ts @@ -0,0 +1,34 @@ +import 'source-map-support/register'; +import { CloudFrontRequestEvent, CloudFrontResponse, CloudFrontRequest } from 'aws-lambda'; + +const REDIRECT_HOST = process.env.REDIRECT_HOST; +const SUPPORTED_REGIONS = new RegExp(process.env.SUPPORTED_REGIONS); +const DEFAULT_REGION = process.env.DEFAULT_REGION; + +export const handler = async (event: CloudFrontRequestEvent): Promise => { + let request = event.Records[0].cf.request; + + let redirectURL = `https://${REDIRECT_HOST}/`; + if (request.headers['cloudfront-viewer-country']) { + const countryCode = request.headers['cloudfront-viewer-country'][0].value; + if (SUPPORTED_REGIONS.test(countryCode)) { + redirectURL = `${redirectURL}${countryCode.toLowerCase()}${request.uri}`; + } else { + redirectURL = `${redirectURL}${DEFAULT_REGION.toLowerCase()}${request.uri}`; + } + + return { + status: '302', + statusDescription: 'Found', + headers: { + location: [{ + key: 'Location', + value: redirectURL, + }], + }, + }; + } + + return request; + +} diff --git a/packages/lambda-at-edge-handlers/package-lock.json b/packages/lambda-at-edge-handlers/package-lock.json index 3ab5d49f..6d78e486 100644 --- a/packages/lambda-at-edge-handlers/package-lock.json +++ b/packages/lambda-at-edge-handlers/package-lock.json @@ -15,9 +15,9 @@ } }, "node_modules/@types/aws-lambda": { - "version": "8.10.108", - "resolved": "https://registry.npmjs.org/@types/aws-lambda/-/aws-lambda-8.10.108.tgz", - "integrity": "sha512-1yh1W1WoqK3lGHy+V/Fi55zobxrDHUUsluCWdMlOXkCvtsCmHPXOG+CQ2STIL4B1g6xi6I6XzxaF8V9+zeIFLA==" + "version": "8.10.109", + "resolved": "https://registry.npmjs.org/@types/aws-lambda/-/aws-lambda-8.10.109.tgz", + "integrity": "sha512-/ME92FneNyXQzrAfcnQQlW1XkCZGPDlpi2ao1MJwecN+6SbeonKeggU8eybv1DfKli90FAVT1MlIZVXfwVuCyg==" }, "node_modules/buffer-from": { "version": "1.1.2", @@ -53,9 +53,9 @@ }, "dependencies": { "@types/aws-lambda": { - "version": "8.10.108", - "resolved": "https://registry.npmjs.org/@types/aws-lambda/-/aws-lambda-8.10.108.tgz", - "integrity": "sha512-1yh1W1WoqK3lGHy+V/Fi55zobxrDHUUsluCWdMlOXkCvtsCmHPXOG+CQ2STIL4B1g6xi6I6XzxaF8V9+zeIFLA==" + "version": "8.10.109", + "resolved": "https://registry.npmjs.org/@types/aws-lambda/-/aws-lambda-8.10.109.tgz", + "integrity": "sha512-/ME92FneNyXQzrAfcnQQlW1XkCZGPDlpi2ao1MJwecN+6SbeonKeggU8eybv1DfKli90FAVT1MlIZVXfwVuCyg==" }, "buffer-from": { "version": "1.1.2", diff --git a/packages/lambda-at-edge-handlers/package.json b/packages/lambda-at-edge-handlers/package.json index 250092e4..d7dac0fd 100644 --- a/packages/lambda-at-edge-handlers/package.json +++ b/packages/lambda-at-edge-handlers/package.json @@ -21,6 +21,7 @@ "dependencies": { "@types/aws-lambda": "^8.10.77", "esbuild": "0.12.15", - "source-map-support": "^0.5.16" + "source-map-support": "^0.5.16", + "axios": "^0.21.1" } } From d331e4fc7e1340f71a08caaa9d5b41d813ae0203 Mon Sep 17 00:00:00 2001 From: Krishan Thisera Date: Tue, 29 Nov 2022 14:22:15 +1030 Subject: [PATCH 09/10] DO-1410: Fixed some type issues --- packages/lambda-at-edge-handlers/lib/error-response.ts | 3 ++- packages/lambda-at-edge-handlers/lib/redirect.ts | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/lambda-at-edge-handlers/lib/error-response.ts b/packages/lambda-at-edge-handlers/lib/error-response.ts index c4e44903..e069bad3 100644 --- a/packages/lambda-at-edge-handlers/lib/error-response.ts +++ b/packages/lambda-at-edge-handlers/lib/error-response.ts @@ -38,7 +38,8 @@ export const handler = ( return instance .get(`https://${FRONTEND_HOST}${PATH_PREFIX}/index.html`) .then((res) => { - response.body = res.data; + // Commenting this as there is body is not defined in the CloudFrontResponse type + // response.body = res.data; response.headers["content-type"] = [ { diff --git a/packages/lambda-at-edge-handlers/lib/redirect.ts b/packages/lambda-at-edge-handlers/lib/redirect.ts index fe260ccc..24820cb7 100644 --- a/packages/lambda-at-edge-handlers/lib/redirect.ts +++ b/packages/lambda-at-edge-handlers/lib/redirect.ts @@ -1,9 +1,9 @@ import 'source-map-support/register'; import { CloudFrontRequestEvent, CloudFrontResponse, CloudFrontRequest } from 'aws-lambda'; -const REDIRECT_HOST = process.env.REDIRECT_HOST; -const SUPPORTED_REGIONS = new RegExp(process.env.SUPPORTED_REGIONS); -const DEFAULT_REGION = process.env.DEFAULT_REGION; +const REDIRECT_HOST = process.env.REDIRECT_HOST || ''; +const SUPPORTED_REGIONS = new RegExp( process.env.SUPPORTED_REGIONS || '') +const DEFAULT_REGION = process.env.DEFAULT_REGION || ''; export const handler = async (event: CloudFrontRequestEvent): Promise => { let request = event.Records[0].cf.request; From 600d22032a4254d51691922de4d2e9ff2bc3d846 Mon Sep 17 00:00:00 2001 From: Krishan Thisera Date: Tue, 29 Nov 2022 14:32:47 +1030 Subject: [PATCH 10/10] DO-1410: Updated package-lock file. Axios install --- package-lock.json | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/package-lock.json b/package-lock.json index 4bbc512f..b0132bd1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2543,6 +2543,14 @@ "fsevents": "2.3.2" } }, + "node_modules/axios": { + "version": "0.21.4", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.21.4.tgz", + "integrity": "sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==", + "dependencies": { + "follow-redirects": "^1.14.0" + } + }, "node_modules/babel-jest": { "version": "26.6.3", "resolved": "https://registry.npmjs.org/babel-jest/-/babel-jest-26.6.3.tgz", @@ -3708,6 +3716,25 @@ "node": ">=8" } }, + "node_modules/follow-redirects": { + "version": "1.15.2", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.2.tgz", + "integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==", + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/RubenVerborgh" + } + ], + "engines": { + "node": ">=4.0" + }, + "peerDependenciesMeta": { + "debug": { + "optional": true + } + } + }, "node_modules/for-in": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/for-in/-/for-in-1.0.2.tgz", @@ -7764,6 +7791,7 @@ "license": "GPL-3.0-only", "dependencies": { "@types/aws-lambda": "^8.10.77", + "axios": "^0.21.1", "esbuild": "0.12.15", "source-map-support": "^0.5.16" } @@ -8058,6 +8086,7 @@ "version": "file:packages/lambda-at-edge-handlers", "requires": { "@types/aws-lambda": "^8.10.77", + "axios": "^0.21.1", "esbuild": "0.12.15", "source-map-support": "^0.5.16" } @@ -9923,6 +9952,14 @@ "fsevents": "2.3.2" } }, + "axios": { + "version": "0.21.4", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.21.4.tgz", + "integrity": "sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==", + "requires": { + "follow-redirects": "^1.14.0" + } + }, "babel-jest": { "version": "26.6.3", "resolved": "https://registry.npmjs.org/babel-jest/-/babel-jest-26.6.3.tgz", @@ -10830,6 +10867,11 @@ "path-exists": "^4.0.0" } }, + "follow-redirects": { + "version": "1.15.2", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.2.tgz", + "integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==" + }, "for-in": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/for-in/-/for-in-1.0.2.tgz",