Skip to content

Commit 1d27a99

Browse files
authored
fix: follow redirects when downloading a file from the CDN (#1719)
* fix: follow redirects when downloading a file from the CDN * style: lint * chore: undo change I made to the test command * chore: lower max redirects
1 parent 04bcac0 commit 1d27a99

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

package-lock.json

+26
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/runtime/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"chalk": "^4.1.2",
1919
"destr": "^1.1.1",
2020
"execa": "^5.1.1",
21+
"follow-redirects": "^1.15.2",
2122
"fs-extra": "^10.0.0",
2223
"globby": "^11.0.4",
2324
"merge-stream": "^2.0.0",

packages/runtime/src/templates/handlerUtils.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import fs, { createWriteStream, existsSync } from 'fs'
2-
import http from 'http'
3-
import https from 'https'
42
import { tmpdir } from 'os'
53
import path from 'path'
64
import { pipeline } from 'stream'
75
import { promisify } from 'util'
86

7+
import { http, https } from 'follow-redirects'
98
import type NextNodeServer from 'next/dist/server/next-server'
109

1110
export type NextServerType = typeof NextNodeServer
@@ -22,7 +21,7 @@ export const downloadFile = async (url: string, destination: string): Promise<vo
2221
const httpx = url.startsWith('https') ? https : http
2322

2423
await new Promise((resolve, reject) => {
25-
const req = httpx.get(url, { timeout: 10000 }, (response) => {
24+
const req = httpx.get(url, { timeout: 10000, maxRedirects: 1 }, (response) => {
2625
if (response.statusCode < 200 || response.statusCode > 299) {
2726
reject(new Error(`Failed to download ${url}: ${response.statusCode} ${response.statusMessage || ''}`))
2827
return

0 commit comments

Comments
 (0)