@opennextjs/aws 3.10.4 → 4.0.1
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.
|
@@ -1,17 +1,32 @@
|
|
|
1
1
|
//#override imports
|
|
2
2
|
import { fetchExternalImage, fetchInternalImage, imageOptimizer, } from "next/dist/server/image-optimizer";
|
|
3
|
+
import { compareSemver } from "../../../utils/semver.js";
|
|
3
4
|
import { debug } from "../../logger.js";
|
|
4
5
|
//#override optimizeImage
|
|
5
6
|
export async function optimizeImage(headers, imageParams, nextConfig, handleRequest) {
|
|
6
7
|
const { isAbsolute, href } = imageParams;
|
|
8
|
+
// Signature for the fetch Image functions have changed in Next.js 15.5.16 and 16.2.5, so we need to check the version to determine how to call them.
|
|
9
|
+
const isAfter1625 = compareSemver(globalThis.nextVersion, ">=", "16.2.5");
|
|
10
|
+
const isAfter15516 = compareSemver(globalThis.nextVersion, ">=", "15.5.16") &&
|
|
11
|
+
compareSemver(globalThis.nextVersion, "<", "16");
|
|
12
|
+
const isNewArgsForInternalFetch = isAfter1625 || isAfter15516;
|
|
13
|
+
// The default value for maximumResponseBody is 50KB in Next code
|
|
14
|
+
// https://github.com/vercel/next.js/blob/0f38c522/packages/next/src/shared/lib/image-config.ts#L164
|
|
15
|
+
const maximumResponseBody = nextConfig.images?.maximumResponseBody || 50_000_000;
|
|
7
16
|
const imageUpstream = isAbsolute
|
|
8
|
-
?
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
17
|
+
? // https://github.com/vercel/next.js/blob/bfe2ab4/packages/next/src/server/image-optimizer.ts#L711
|
|
18
|
+
await (isNewArgsForInternalFetch
|
|
19
|
+
? fetchExternalImage(href, false, maximumResponseBody)
|
|
20
|
+
: //@ts-expect-error - fetchExternalImage signature has changed in Next.js 16, it has an extra boolean parameter.
|
|
21
|
+
fetchExternalImage(href))
|
|
22
|
+
: await (isNewArgsForInternalFetch
|
|
23
|
+
? fetchInternalImage(href,
|
|
24
|
+
// @ts-expect-error - It is supposed to be an IncomingMessage object, but only the headers are used.
|
|
25
|
+
{ headers }, {}, // res object is not necessary as it's not actually used.
|
|
26
|
+
maximumResponseBody, handleRequest)
|
|
27
|
+
: // @ts-expect-error - fetchInternalImage signature has changed in Next.js 15.5.16 and 16.2.5
|
|
28
|
+
fetchInternalImage(href, { headers }, {}, // res object is not necessary as it's not actually used.
|
|
29
|
+
handleRequest));
|
|
15
30
|
const result = await imageOptimizer(imageUpstream, imageParams,
|
|
16
31
|
// @ts-ignore
|
|
17
32
|
nextConfig, false);
|
|
@@ -119,7 +119,7 @@ async function generateResult(event, localizedPath, cachedValue, lastModified, i
|
|
|
119
119
|
let isDataRequest = false;
|
|
120
120
|
let additionalHeaders = {};
|
|
121
121
|
if (cachedValue.type === "app") {
|
|
122
|
-
isDataRequest =
|
|
122
|
+
isDataRequest = event.headers.rsc === "1";
|
|
123
123
|
if (isDataRequest) {
|
|
124
124
|
const { body: appRouterBody, additionalHeaders: appHeaders } = getBodyForAppRouter(event, cachedValue);
|
|
125
125
|
body = appRouterBody;
|
|
@@ -208,7 +208,7 @@ function handleTrailingSlashRedirect(event) {
|
|
|
208
208
|
}
|
|
209
209
|
const emptyBody = emptyReadableStream();
|
|
210
210
|
if (NextConfig.trailingSlash &&
|
|
211
|
-
!event.
|
|
211
|
+
!(event.query.__nextDataReq === "1") &&
|
|
212
212
|
!event.rawPath.endsWith("/") &&
|
|
213
213
|
!event.rawPath.match(/[\w-]+\.[\w]+$/g)) {
|
|
214
214
|
const headersLocation = event.url.split("?");
|
|
@@ -23,6 +23,22 @@ const geoHeaderToNextHeader = {
|
|
|
23
23
|
"x-open-next-latitude": "x-vercel-ip-latitude",
|
|
24
24
|
"x-open-next-longitude": "x-vercel-ip-longitude",
|
|
25
25
|
};
|
|
26
|
+
// Those are internal headers from Next.js that should not be set by users
|
|
27
|
+
// We strip them for the incoming request - To be updated when Next.js adds new internal headers
|
|
28
|
+
// https://github.com/vercel/next.js/blob/ed1c6cc/packages/next/src/server/lib/server-ipc/utils.ts#L42-L53
|
|
29
|
+
// NOTE: Use lowercase format.
|
|
30
|
+
const NEXT_INTERNAL_HEADERS = [
|
|
31
|
+
"x-middleware-rewrite",
|
|
32
|
+
"x-middleware-redirect",
|
|
33
|
+
"x-middleware-set-cookie",
|
|
34
|
+
"x-middleware-skip",
|
|
35
|
+
"x-middleware-override-headers",
|
|
36
|
+
"x-middleware-next",
|
|
37
|
+
"x-now-route-matches",
|
|
38
|
+
"x-matched-path",
|
|
39
|
+
"x-nextjs-data",
|
|
40
|
+
"x-next-resume-state-length",
|
|
41
|
+
];
|
|
26
42
|
/**
|
|
27
43
|
* Adds the middleware headers to an event or result.
|
|
28
44
|
*
|
|
@@ -53,8 +69,10 @@ export default async function routingHandler(event, { assetResolver }) {
|
|
|
53
69
|
// First we remove internal headers
|
|
54
70
|
// We don't want to allow users to set these headers
|
|
55
71
|
for (const key of Object.keys(event.headers)) {
|
|
56
|
-
|
|
57
|
-
|
|
72
|
+
const lowerCaseKey = key.toLowerCase();
|
|
73
|
+
if (lowerCaseKey.startsWith(INTERNAL_HEADER_PREFIX) ||
|
|
74
|
+
lowerCaseKey.startsWith(MIDDLEWARE_HEADER_PREFIX) ||
|
|
75
|
+
NEXT_INTERNAL_HEADERS.includes(lowerCaseKey)) {
|
|
58
76
|
delete event.headers[key];
|
|
59
77
|
}
|
|
60
78
|
}
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"access": "public"
|
|
4
4
|
},
|
|
5
5
|
"name": "@opennextjs/aws",
|
|
6
|
-
"version": "
|
|
6
|
+
"version": "4.0.1",
|
|
7
7
|
"bin": {
|
|
8
8
|
"open-next": "./dist/index.js"
|
|
9
9
|
},
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"typescript": "5.9.3"
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
63
|
-
"next": ">=15.5.
|
|
63
|
+
"next": ">=15.5.16 <16 || >=16.2.5"
|
|
64
64
|
},
|
|
65
65
|
"bugs": {
|
|
66
66
|
"url": "https://github.com/opennextjs/opennextjs-aws/issues"
|