@opennextjs/aws 4.0.2 → 4.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -5,46 +5,62 @@ import { debug } from "../../logger.js";
|
|
|
5
5
|
//#override optimizeImage
|
|
6
6
|
export async function optimizeImage(headers, imageParams, nextConfig, handleRequest) {
|
|
7
7
|
const { isAbsolute, href } = imageParams;
|
|
8
|
-
// Signature for the fetch Image functions have changed across Next.js versions.
|
|
9
|
-
const isV15After15510 = compareSemver(globalThis.nextVersion, ">=", "15.5.10") &&
|
|
10
|
-
compareSemver(globalThis.nextVersion, "<", "16");
|
|
11
|
-
const isV15After15515 = compareSemver(globalThis.nextVersion, ">=", "15.5.16") &&
|
|
12
|
-
compareSemver(globalThis.nextVersion, "<", "16");
|
|
13
|
-
const isV16Plus = compareSemver(globalThis.nextVersion, ">=", "16");
|
|
14
|
-
const isAfter1615 = compareSemver(globalThis.nextVersion, ">=", "16.1.5");
|
|
15
|
-
const isAfter1625 = compareSemver(globalThis.nextVersion, ">=", "16.2.5");
|
|
16
|
-
// fetchInternalImage signature varies across Next.js versions:
|
|
17
|
-
// <=v15.5.15, v16.0.0–v16.2.4: fetchInternalImage(href, req, res, handleRequest)
|
|
18
|
-
// v15.5.16–v15.x, v16.2.5+: fetchInternalImage(href, req, res, maximumResponseBody, handleRequest)
|
|
19
|
-
const isNewArgsForInternalFetch = isAfter1625 || isV15After15515;
|
|
20
|
-
// fetchExternalImage signature varies across Next.js versions:
|
|
21
|
-
// <=v15.5.9: fetchExternalImage(href)
|
|
22
|
-
// v15.5.10–v15.x: fetchExternalImage(href, maximumResponseBody)
|
|
23
|
-
// v16.0.0–v16.1.4: fetchExternalImage(href, dangerouslyAllowLocalIP)
|
|
24
|
-
// v16.1.5+: fetchExternalImage(href, dangerouslyAllowLocalIP, maximumResponseBody)
|
|
25
8
|
// The default value for maximumResponseBody is 50KB in Next code
|
|
26
9
|
// https://github.com/vercel/next.js/blob/0f38c522/packages/next/src/shared/lib/image-config.ts#L164
|
|
27
10
|
const maximumResponseBody = nextConfig.images?.maximumResponseBody || 50_000_000;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
11
|
+
/**
|
|
12
|
+
* fetchExternalImage signature varies across Next.js versions:
|
|
13
|
+
* <=v15.5.9: fetchExternalImage(href)
|
|
14
|
+
* v15.5.10–v15.x: fetchExternalImage(href, maximumResponseBody)
|
|
15
|
+
* v16.0.0–v16.1.4: fetchExternalImage(href, dangerouslyAllowLocalIP)
|
|
16
|
+
* v16.1.5+: fetchExternalImage(href, dangerouslyAllowLocalIP, maximumResponseBody)
|
|
17
|
+
*
|
|
18
|
+
* https://github.com/vercel/next.js/blob/bfe2ab4/packages/next/src/server/image-optimizer.ts#L711
|
|
19
|
+
*/
|
|
20
|
+
const callFetchExternalImage = () => {
|
|
21
|
+
const version = globalThis.nextVersion;
|
|
22
|
+
// v16.1.5+
|
|
23
|
+
if (compareSemver(version, ">=", "16.1.5")) {
|
|
24
|
+
return fetchExternalImage(href, false, maximumResponseBody);
|
|
25
|
+
}
|
|
26
|
+
// v16.0.0–v16.1.4
|
|
27
|
+
if (compareSemver(version, ">=", "16")) {
|
|
28
|
+
// @ts-expect-error - fetchExternalImage signature varies across Next.js versions
|
|
29
|
+
return fetchExternalImage(href, false);
|
|
30
|
+
}
|
|
31
|
+
// v15.5.10–v15.x
|
|
32
|
+
if (compareSemver(version, ">=", "15.5.10")) {
|
|
33
|
+
// @ts-expect-error - fetchExternalImage signature varies across Next.js versions
|
|
34
|
+
return fetchExternalImage(href, maximumResponseBody);
|
|
35
|
+
}
|
|
36
|
+
// <=v15.5.9
|
|
37
|
+
// @ts-expect-error - fetchExternalImage signature varies across Next.js versions
|
|
38
|
+
return fetchExternalImage(href);
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* fetchInternalImage signature varies across Next.js versions:
|
|
42
|
+
* <=v15.5.15, v16.0.0–v16.2.4: fetchInternalImage(href, req, res, handleRequest)
|
|
43
|
+
* v15.5.16–v15.x, v16.2.5+: fetchInternalImage(href, req, res, maximumResponseBody, handleRequest)
|
|
44
|
+
*/
|
|
45
|
+
const callFetchInternalImage = () => {
|
|
46
|
+
const version = globalThis.nextVersion;
|
|
47
|
+
const isV15WithNewArgs = compareSemver(version, ">=", "15.5.16") &&
|
|
48
|
+
compareSemver(version, "<", "16");
|
|
49
|
+
// v15.5.16–v15.x, v16.2.5+
|
|
50
|
+
if (isV15WithNewArgs || compareSemver(version, ">=", "16.2.5")) {
|
|
51
|
+
return fetchInternalImage(href,
|
|
42
52
|
// @ts-expect-error - It is supposed to be an IncomingMessage object, but only the headers are used.
|
|
43
53
|
{ headers }, {}, // res object is not necessary as it's not actually used.
|
|
44
|
-
maximumResponseBody, handleRequest)
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
54
|
+
maximumResponseBody, handleRequest);
|
|
55
|
+
}
|
|
56
|
+
// <=v15.5.15, v16.0.0–v16.2.4
|
|
57
|
+
// @ts-expect-error - fetchInternalImage signature has changed in Next.js 15.5.16 and 16.2.5
|
|
58
|
+
return fetchInternalImage(href, { headers }, {}, // res object is not necessary as it's not actually used.
|
|
59
|
+
handleRequest);
|
|
60
|
+
};
|
|
61
|
+
const imageUpstream = isAbsolute
|
|
62
|
+
? await callFetchExternalImage()
|
|
63
|
+
: await callFetchInternalImage();
|
|
48
64
|
const result = await imageOptimizer(imageUpstream, imageParams,
|
|
49
65
|
// @ts-ignore
|
|
50
66
|
nextConfig, false);
|
|
@@ -287,6 +287,10 @@ export function fixDataPage(internalEvent, buildId) {
|
|
|
287
287
|
...internalEvent,
|
|
288
288
|
rawPath: newPath,
|
|
289
289
|
query,
|
|
290
|
+
headers: {
|
|
291
|
+
...internalEvent.headers,
|
|
292
|
+
"x-nextjs-data": "1",
|
|
293
|
+
},
|
|
290
294
|
url: new URL(`${newPath}${convertToQueryString(query)}`, internalEvent.url).href,
|
|
291
295
|
};
|
|
292
296
|
}
|