From 4a6444efa5a348a7793b2b37a7d2a177f04de340 Mon Sep 17 00:00:00 2001 From: Erica Pisani Date: Wed, 26 Oct 2022 14:26:17 -0400 Subject: [PATCH 1/4] fix: follow redirects when downloading a file from the CDN --- package-lock.json | 38 ++++++++++++++++--- package.json | 2 +- packages/runtime/package.json | 1 + .../runtime/src/templates/handlerUtils.ts | 3 +- 4 files changed, 35 insertions(+), 9 deletions(-) diff --git a/package-lock.json b/package-lock.json index 70c4ac10ad..cc01cb91f4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5238,9 +5238,9 @@ "devOptional": true }, "node_modules/@types/react": { - "version": "17.0.50", - "resolved": "https://registry.npmjs.org/@types/react/-/react-17.0.50.tgz", - "integrity": "sha512-ZCBHzpDb5skMnc1zFXAXnL3l1FAdi+xZvwxK+PkglMmBrwjpp9nKaWuEvrGnSifCJmBFGxZOOFuwC6KH/s0NuA==", + "version": "17.0.51", + "resolved": "https://registry.npmjs.org/@types/react/-/react-17.0.51.tgz", + "integrity": "sha512-YMddzAE+nSH04BiTJ5GydTxk0/3hckqyuOclg0s6zQYj/XzfRVNzHZAFwZb5SCSavkzTYUtcq/gwjLnvt2Y4cg==", "devOptional": true, "dependencies": { "@types/prop-types": "*", @@ -11884,6 +11884,25 @@ "node": ">=10" } }, + "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", @@ -23201,6 +23220,7 @@ "chalk": "^4.1.2", "destr": "^1.1.1", "execa": "^5.1.1", + "follow-redirects": "^1.15.2", "fs-extra": "^10.0.0", "globby": "^11.0.4", "merge-stream": "^2.0.0", @@ -26109,6 +26129,7 @@ "chalk": "^4.1.2", "destr": "^1.1.1", "execa": "^5.1.1", + "follow-redirects": "^1.15.2", "fs-extra": "^10.0.0", "globby": "^11.0.4", "merge-stream": "^2.0.0", @@ -26905,9 +26926,9 @@ "devOptional": true }, "@types/react": { - "version": "17.0.50", - "resolved": "https://registry.npmjs.org/@types/react/-/react-17.0.50.tgz", - "integrity": "sha512-ZCBHzpDb5skMnc1zFXAXnL3l1FAdi+xZvwxK+PkglMmBrwjpp9nKaWuEvrGnSifCJmBFGxZOOFuwC6KH/s0NuA==", + "version": "17.0.51", + "resolved": "https://registry.npmjs.org/@types/react/-/react-17.0.51.tgz", + "integrity": "sha512-YMddzAE+nSH04BiTJ5GydTxk0/3hckqyuOclg0s6zQYj/XzfRVNzHZAFwZb5SCSavkzTYUtcq/gwjLnvt2Y4cg==", "devOptional": true, "requires": { "@types/prop-types": "*", @@ -32015,6 +32036,11 @@ "tslib": "^2.0.3" } }, + "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", diff --git a/package.json b/package.json index b3e693ef93..cc9c1b0e36 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "postinstall": "run-s build install-husky", "install-husky": "if-env CI=1 || husky install node_modules/@netlify/eslint-config-node/.husky", "test": "run-s build:demo test:jest", - "test:jest": "jest", + "test:jest": "jest --watch", "test:jest:update": "jest --updateSnapshot", "test:update": "run-s build build:demo test:jest:update" }, diff --git a/packages/runtime/package.json b/packages/runtime/package.json index c48865617d..33da3eaeaa 100644 --- a/packages/runtime/package.json +++ b/packages/runtime/package.json @@ -18,6 +18,7 @@ "chalk": "^4.1.2", "destr": "^1.1.1", "execa": "^5.1.1", + "follow-redirects": "^1.15.2", "fs-extra": "^10.0.0", "globby": "^11.0.4", "merge-stream": "^2.0.0", diff --git a/packages/runtime/src/templates/handlerUtils.ts b/packages/runtime/src/templates/handlerUtils.ts index b877dfbcd7..c692d7cdbb 100644 --- a/packages/runtime/src/templates/handlerUtils.ts +++ b/packages/runtime/src/templates/handlerUtils.ts @@ -1,6 +1,5 @@ import fs, { createWriteStream, existsSync } from 'fs' -import http from 'http' -import https from 'https' +import { http, https } from 'follow-redirects' import { tmpdir } from 'os' import path from 'path' import { pipeline } from 'stream' From f798f42dfde43501b52810bff65473dcaea73971 Mon Sep 17 00:00:00 2001 From: Erica Pisani Date: Wed, 26 Oct 2022 14:26:52 -0400 Subject: [PATCH 2/4] style: lint --- packages/runtime/src/templates/handlerUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/runtime/src/templates/handlerUtils.ts b/packages/runtime/src/templates/handlerUtils.ts index c692d7cdbb..b5a18610d6 100644 --- a/packages/runtime/src/templates/handlerUtils.ts +++ b/packages/runtime/src/templates/handlerUtils.ts @@ -1,10 +1,10 @@ import fs, { createWriteStream, existsSync } from 'fs' -import { http, https } from 'follow-redirects' import { tmpdir } from 'os' import path from 'path' import { pipeline } from 'stream' import { promisify } from 'util' +import { http, https } from 'follow-redirects' import type NextNodeServer from 'next/dist/server/next-server' export type NextServerType = typeof NextNodeServer From 508a75612a624a1ecdb8d602cfd23162d0f9e830 Mon Sep 17 00:00:00 2001 From: Erica Pisani Date: Wed, 26 Oct 2022 14:36:25 -0400 Subject: [PATCH 3/4] chore: undo change I made to the test command --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index cc9c1b0e36..b3e693ef93 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "postinstall": "run-s build install-husky", "install-husky": "if-env CI=1 || husky install node_modules/@netlify/eslint-config-node/.husky", "test": "run-s build:demo test:jest", - "test:jest": "jest --watch", + "test:jest": "jest", "test:jest:update": "jest --updateSnapshot", "test:update": "run-s build build:demo test:jest:update" }, From 52992be5f9fa94b6a15f39af07168e11fc76f468 Mon Sep 17 00:00:00 2001 From: Erica Pisani Date: Wed, 26 Oct 2022 15:23:24 -0400 Subject: [PATCH 4/4] chore: lower max redirects --- packages/runtime/src/templates/handlerUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/runtime/src/templates/handlerUtils.ts b/packages/runtime/src/templates/handlerUtils.ts index b5a18610d6..b68a8b5f30 100644 --- a/packages/runtime/src/templates/handlerUtils.ts +++ b/packages/runtime/src/templates/handlerUtils.ts @@ -21,7 +21,7 @@ export const downloadFile = async (url: string, destination: string): Promise { - const req = httpx.get(url, { timeout: 10000 }, (response) => { + const req = httpx.get(url, { timeout: 10000, maxRedirects: 1 }, (response) => { if (response.statusCode < 200 || response.statusCode > 299) { reject(new Error(`Failed to download ${url}: ${response.statusCode} ${response.statusMessage || ''}`)) return