@opennextjs/aws 3.2.0 → 3.2.2
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.
- package/README.md +15 -1
- package/dist/adapters/cache.d.ts +1 -23
- package/dist/adapters/cache.js +22 -18
- package/dist/adapters/config/index.js +1 -1
- package/dist/adapters/config/util.js +2 -2
- package/dist/adapters/dynamo-provider.js +3 -5
- package/dist/adapters/edge-adapter.d.ts +0 -3
- package/dist/adapters/edge-adapter.js +43 -38
- package/dist/adapters/image-optimization-adapter.js +4 -4
- package/dist/adapters/logger.d.ts +0 -3
- package/dist/adapters/logger.js +3 -5
- package/dist/adapters/middleware.js +42 -18
- package/dist/adapters/plugins/image-optimization/image-optimization.d.ts +0 -3
- package/dist/adapters/plugins/image-optimization/image-optimization.replacement.d.ts +0 -3
- package/dist/adapters/revalidate.js +2 -2
- package/dist/adapters/server-adapter.d.ts +0 -3
- package/dist/adapters/server-adapter.js +3 -1
- package/dist/adapters/util.js +2 -2
- package/dist/build/bundleNextServer.d.ts +3 -1
- package/dist/build/bundleNextServer.js +3 -3
- package/dist/build/compileConfig.js +3 -3
- package/dist/build/copyTracedFiles.js +16 -27
- package/dist/build/createAssets.js +35 -26
- package/dist/build/createImageOptimizationBundle.js +4 -1
- package/dist/build/createMiddleware.d.ts +4 -4
- package/dist/build/createMiddleware.js +16 -19
- package/dist/build/createRevalidationBundle.js +1 -1
- package/dist/build/createServerBundle.js +34 -45
- package/dist/build/createWarmerBundle.js +1 -1
- package/dist/build/edge/createEdgeBundle.d.ts +9 -7
- package/dist/build/edge/createEdgeBundle.js +19 -14
- package/dist/build/generateOutput.js +7 -13
- package/dist/build/helper.d.ts +22 -4
- package/dist/build/helper.js +26 -12
- package/dist/build/installDeps.js +12 -2
- package/dist/build/patch/patchedAsyncStorage.js +1 -1
- package/dist/build/utils.js +3 -2
- package/dist/build/validateConfig.js +1 -0
- package/dist/core/createGenericHandler.d.ts +2 -4
- package/dist/core/createGenericHandler.js +6 -7
- package/dist/core/createMainHandler.d.ts +0 -17
- package/dist/core/createMainHandler.js +10 -9
- package/dist/core/edgeFunctionHandler.d.ts +1 -51
- package/dist/core/patchAsyncStorage.js +5 -6
- package/dist/core/requestHandler.js +98 -89
- package/dist/core/require-hooks.js +8 -7
- package/dist/core/resolve.d.ts +13 -7
- package/dist/core/resolve.js +29 -35
- package/dist/core/routing/cacheInterceptor.js +12 -13
- package/dist/core/routing/i18n/accept-header.js +3 -2
- package/dist/core/routing/matcher.d.ts +2 -4
- package/dist/core/routing/matcher.js +29 -31
- package/dist/core/routing/middleware.js +22 -18
- package/dist/core/routing/util.d.ts +0 -13
- package/dist/core/routing/util.js +32 -91
- package/dist/core/routingHandler.d.ts +2 -0
- package/dist/core/routingHandler.js +30 -12
- package/dist/core/util.js +5 -3
- package/dist/helpers/withSST.d.ts +1 -1
- package/dist/http/openNextResponse.d.ts +5 -9
- package/dist/http/openNextResponse.js +29 -31
- package/dist/http/request.d.ts +0 -3
- package/dist/http/request.js +4 -2
- package/dist/http/util.d.ts +1 -1
- package/dist/http/util.js +8 -12
- package/dist/minimize-js.js +19 -19
- package/dist/overrides/converters/aws-apigw-v1.d.ts +2 -2
- package/dist/overrides/converters/aws-apigw-v1.js +2 -1
- package/dist/overrides/converters/aws-apigw-v2.d.ts +2 -2
- package/dist/overrides/converters/aws-apigw-v2.js +6 -7
- package/dist/overrides/converters/aws-cloudfront.d.ts +2 -2
- package/dist/overrides/converters/aws-cloudfront.js +11 -30
- package/dist/overrides/converters/dummy.d.ts +1 -1
- package/dist/overrides/converters/edge.d.ts +5 -1
- package/dist/overrides/converters/edge.js +16 -17
- package/dist/overrides/converters/node.d.ts +1 -1
- package/dist/overrides/converters/node.js +1 -1
- package/dist/overrides/converters/sqs-revalidate.d.ts +1 -1
- package/dist/overrides/imageLoader/dummy.d.ts +1 -1
- package/dist/overrides/imageLoader/host.d.ts +1 -1
- package/dist/overrides/imageLoader/s3.d.ts +1 -1
- package/dist/overrides/imageLoader/s3.js +1 -1
- package/dist/overrides/incrementalCache/dummy.d.ts +1 -1
- package/dist/overrides/incrementalCache/s3-lite.d.ts +1 -1
- package/dist/overrides/incrementalCache/s3-lite.js +15 -19
- package/dist/overrides/incrementalCache/s3.d.ts +1 -1
- package/dist/overrides/incrementalCache/s3.js +1 -1
- package/dist/overrides/originResolver/dummy.d.ts +1 -1
- package/dist/overrides/originResolver/pattern-env.d.ts +1 -1
- package/dist/overrides/originResolver/pattern-env.js +10 -11
- package/dist/overrides/proxyExternalRequest/dummy.d.ts +3 -0
- package/dist/overrides/proxyExternalRequest/dummy.js +7 -0
- package/dist/overrides/proxyExternalRequest/fetch.d.ts +3 -0
- package/dist/overrides/proxyExternalRequest/fetch.js +25 -0
- package/dist/overrides/proxyExternalRequest/node.d.ts +3 -0
- package/dist/overrides/proxyExternalRequest/node.js +67 -0
- package/dist/overrides/queue/dummy.d.ts +1 -1
- package/dist/overrides/queue/sqs-lite.d.ts +1 -1
- package/dist/overrides/queue/sqs-lite.js +7 -9
- package/dist/overrides/queue/sqs.d.ts +1 -1
- package/dist/overrides/queue/sqs.js +1 -1
- package/dist/overrides/tagCache/constants.js +2 -2
- package/dist/overrides/tagCache/dummy.d.ts +1 -1
- package/dist/overrides/tagCache/dynamodb-lite.d.ts +1 -1
- package/dist/overrides/tagCache/dynamodb-lite.js +10 -12
- package/dist/overrides/tagCache/dynamodb.d.ts +1 -1
- package/dist/overrides/tagCache/dynamodb.js +2 -2
- package/dist/overrides/warmer/aws-lambda.d.ts +1 -1
- package/dist/overrides/warmer/dummy.d.ts +1 -1
- package/dist/overrides/wrappers/aws-lambda-streaming.d.ts +2 -2
- package/dist/overrides/wrappers/aws-lambda.d.ts +2 -2
- package/dist/overrides/wrappers/cloudflare.d.ts +2 -1
- package/dist/overrides/wrappers/cloudflare.js +21 -3
- package/dist/overrides/wrappers/dummy.d.ts +2 -2
- package/dist/overrides/wrappers/node.d.ts +2 -2
- package/dist/overrides/wrappers/node.js +3 -3
- package/dist/plugins/edge.d.ts +3 -2
- package/dist/plugins/edge.js +33 -34
- package/dist/plugins/replacement.d.ts +1 -1
- package/dist/plugins/replacement.js +5 -6
- package/dist/plugins/resolve.d.ts +3 -1
- package/dist/plugins/resolve.js +4 -1
- package/dist/types/aws-lambda.d.ts +2 -5
- package/dist/types/cache.d.ts +0 -2
- package/dist/types/global.d.ts +188 -0
- package/dist/types/next-types.d.ts +1 -3
- package/dist/types/open-next.d.ts +24 -45
- package/dist/types/overrides.d.ts +87 -0
- package/dist/utils/promise.d.ts +3 -0
- package/dist/utils/promise.js +44 -0
- package/dist/utils/stream.d.ts +0 -1
- package/package.json +2 -2
- package/dist/adapters/plugins/without-routing/requestHandler.d.ts +0 -2
- package/dist/adapters/plugins/without-routing/requestHandler.js +0 -10
- package/dist/overrides/incrementalCache/types.d.ts +0 -34
- package/dist/overrides/queue/types.d.ts +0 -12
- package/dist/overrides/tagCache/types.d.ts +0 -11
- package/dist/overrides/tagCache/types.js +0 -1
- /package/dist/{overrides/incrementalCache/types.js → types/global.js} +0 -0
- /package/dist/{overrides/queue/types.js → types/overrides.js} +0 -0
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// Individually compiled modules are as defined for the compilation in bundles/webpack/packages/*.
|
|
4
4
|
import { error } from "../adapters/logger.js";
|
|
5
5
|
// This module will only be loaded once per process.
|
|
6
|
-
const mod = require("module");
|
|
6
|
+
const mod = require("node:module");
|
|
7
7
|
const resolveFilename = mod._resolveFilename;
|
|
8
8
|
const hookPropertyMapApp = new Map();
|
|
9
9
|
const hookPropertyMapPage = new Map();
|
|
@@ -17,7 +17,7 @@ export function overrideHooks(config) {
|
|
|
17
17
|
throw e;
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
|
-
function addHookAliases(aliases
|
|
20
|
+
function addHookAliases(aliases, type) {
|
|
21
21
|
for (const [key, value] of aliases) {
|
|
22
22
|
type === "app"
|
|
23
23
|
? hookPropertyMapApp.set(key, value)
|
|
@@ -68,12 +68,12 @@ function overrideDefault() {
|
|
|
68
68
|
const toResolveMap = (map) => Object.entries(map).map(([key, value]) => [key, require.resolve(value)]);
|
|
69
69
|
// Override built-in React packages if necessary
|
|
70
70
|
function overrideReact(config) {
|
|
71
|
-
addHookAliases([["react", require.resolve(
|
|
71
|
+
addHookAliases([["react", require.resolve("react")]], "page");
|
|
72
72
|
// ignore: react/jsx-dev-runtime is not available on older version of Next.js ie. v13.1.6
|
|
73
73
|
// react/jsx-runtime is not available on newer version of Next.js ie. v13.4.10-canary.3
|
|
74
74
|
try {
|
|
75
|
-
addHookAliases([["react/jsx-runtime", require.resolve(
|
|
76
|
-
addHookAliases([["react/jsx-dev-runtime", require.resolve(
|
|
75
|
+
addHookAliases([["react/jsx-runtime", require.resolve("react/jsx-runtime")]], "page");
|
|
76
|
+
addHookAliases([["react/jsx-dev-runtime", require.resolve("react/jsx-dev-runtime")]], "page");
|
|
77
77
|
}
|
|
78
78
|
catch (e) { }
|
|
79
79
|
if (config.experimental.appDir) {
|
|
@@ -90,13 +90,14 @@ function isApp() {
|
|
|
90
90
|
process.env.__NEXT_PRIVATE_PREBUNDLED_REACT === "experimental");
|
|
91
91
|
}
|
|
92
92
|
export function applyOverride() {
|
|
93
|
-
mod._resolveFilename =
|
|
93
|
+
mod._resolveFilename = ((originalResolveFilename, requestMapApp, requestMapPage, request, parent, isMain, options) => {
|
|
94
94
|
const hookResolved = isApp()
|
|
95
95
|
? requestMapApp.get(request)
|
|
96
96
|
: requestMapPage.get(request);
|
|
97
|
+
// biome-ignore lint/style/noParameterAssign:
|
|
97
98
|
if (hookResolved)
|
|
98
99
|
request = hookResolved;
|
|
99
100
|
return originalResolveFilename.call(mod, request, parent, isMain, options);
|
|
100
101
|
// We use `bind` here to avoid referencing outside variables to create potential memory leaks.
|
|
101
|
-
}.bind(null, resolveFilename, hookPropertyMapApp, hookPropertyMapPage);
|
|
102
|
+
}).bind(null, resolveFilename, hookPropertyMapApp, hookPropertyMapPage);
|
|
102
103
|
}
|
package/dist/core/resolve.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type { BaseEventOrResult,
|
|
2
|
-
import type { TagCache } from "../overrides
|
|
1
|
+
import type { BaseEventOrResult, DefaultOverrideOptions, InternalEvent, InternalResult, OpenNextConfig, OverrideOptions } from "../types/open-next";
|
|
2
|
+
import type { Converter, TagCache, Wrapper } from "../types/overrides";
|
|
3
|
+
type RemoveUndefined<T> = T extends undefined ? never : T;
|
|
3
4
|
export declare function resolveConverter<E extends BaseEventOrResult = InternalEvent, R extends BaseEventOrResult = InternalResult>(converter: DefaultOverrideOptions<E, R>["converter"]): Promise<Converter<E, R>>;
|
|
4
5
|
export declare function resolveWrapper<E extends BaseEventOrResult = InternalEvent, R extends BaseEventOrResult = InternalResult>(wrapper: DefaultOverrideOptions<E, R>["wrapper"]): Promise<Wrapper<E, R>>;
|
|
5
6
|
/**
|
|
@@ -15,26 +16,31 @@ export declare function resolveTagCache(tagCache: OverrideOptions["tagCache"]):
|
|
|
15
16
|
* @returns
|
|
16
17
|
* @__PURE__
|
|
17
18
|
*/
|
|
18
|
-
export declare function resolveQueue(queue: OverrideOptions["queue"]): Promise<import("../overrides
|
|
19
|
+
export declare function resolveQueue(queue: OverrideOptions["queue"]): Promise<import("../types/overrides").Queue>;
|
|
19
20
|
/**
|
|
20
21
|
*
|
|
21
22
|
* @param incrementalCache
|
|
22
23
|
* @returns
|
|
23
24
|
* @__PURE__
|
|
24
25
|
*/
|
|
25
|
-
export declare function resolveIncrementalCache(incrementalCache: OverrideOptions["incrementalCache"]): Promise<import("../overrides
|
|
26
|
+
export declare function resolveIncrementalCache(incrementalCache: OverrideOptions["incrementalCache"]): Promise<import("../types/overrides").IncrementalCache>;
|
|
26
27
|
/**
|
|
27
28
|
* @param imageLoader
|
|
28
29
|
* @returns
|
|
29
30
|
* @__PURE__
|
|
30
31
|
*/
|
|
31
|
-
export declare function resolveImageLoader(imageLoader:
|
|
32
|
+
export declare function resolveImageLoader(imageLoader: RemoveUndefined<OpenNextConfig["imageOptimization"]>["loader"]): Promise<import("../types/overrides").ImageLoader>;
|
|
32
33
|
/**
|
|
33
34
|
* @returns
|
|
34
35
|
* @__PURE__
|
|
35
36
|
*/
|
|
36
|
-
export declare function resolveOriginResolver(originResolver
|
|
37
|
+
export declare function resolveOriginResolver(originResolver: RemoveUndefined<OpenNextConfig["middleware"]>["originResolver"]): Promise<import("../types/overrides").OriginResolver>;
|
|
37
38
|
/**
|
|
38
39
|
* @__PURE__
|
|
39
40
|
*/
|
|
40
|
-
export declare function resolveWarmerInvoke(warmer
|
|
41
|
+
export declare function resolveWarmerInvoke(warmer: RemoveUndefined<OpenNextConfig["warmer"]>["invokeFunction"]): Promise<import("../types/overrides").Warmer>;
|
|
42
|
+
/**
|
|
43
|
+
* @__PURE__
|
|
44
|
+
*/
|
|
45
|
+
export declare function resolveProxyRequest(proxyRequest: OverrideOptions["proxyExternalRequest"]): Promise<import("../types/overrides").ProxyExternalRequest>;
|
|
46
|
+
export {};
|
package/dist/core/resolve.js
CHANGED
|
@@ -2,22 +2,18 @@ export async function resolveConverter(converter) {
|
|
|
2
2
|
if (typeof converter === "function") {
|
|
3
3
|
return converter();
|
|
4
4
|
}
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
return m_1.default;
|
|
9
|
-
}
|
|
5
|
+
const m_1 = await import("../overrides/converters/aws-apigw-v2.js");
|
|
6
|
+
// @ts-expect-error
|
|
7
|
+
return m_1.default;
|
|
10
8
|
}
|
|
11
9
|
export async function resolveWrapper(wrapper) {
|
|
12
10
|
if (typeof wrapper === "function") {
|
|
13
11
|
return wrapper();
|
|
14
12
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return m_1.default;
|
|
20
|
-
}
|
|
13
|
+
// This will be replaced by the bundler
|
|
14
|
+
const m_1 = await import("../overrides/wrappers/aws-lambda.js");
|
|
15
|
+
// @ts-expect-error
|
|
16
|
+
return m_1.default;
|
|
21
17
|
}
|
|
22
18
|
/**
|
|
23
19
|
*
|
|
@@ -29,11 +25,9 @@ export async function resolveTagCache(tagCache) {
|
|
|
29
25
|
if (typeof tagCache === "function") {
|
|
30
26
|
return tagCache();
|
|
31
27
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return m_1.default;
|
|
36
|
-
}
|
|
28
|
+
// This will be replaced by the bundler
|
|
29
|
+
const m_1 = await import("../overrides/tagCache/dynamodb.js");
|
|
30
|
+
return m_1.default;
|
|
37
31
|
}
|
|
38
32
|
/**
|
|
39
33
|
*
|
|
@@ -45,10 +39,8 @@ export async function resolveQueue(queue) {
|
|
|
45
39
|
if (typeof queue === "function") {
|
|
46
40
|
return queue();
|
|
47
41
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
return m_1.default;
|
|
51
|
-
}
|
|
42
|
+
const m_1 = await import("../overrides/queue/sqs.js");
|
|
43
|
+
return m_1.default;
|
|
52
44
|
}
|
|
53
45
|
/**
|
|
54
46
|
*
|
|
@@ -60,10 +52,8 @@ export async function resolveIncrementalCache(incrementalCache) {
|
|
|
60
52
|
if (typeof incrementalCache === "function") {
|
|
61
53
|
return incrementalCache();
|
|
62
54
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
return m_1.default;
|
|
66
|
-
}
|
|
55
|
+
const m_1 = await import("../overrides/incrementalCache/s3.js");
|
|
56
|
+
return m_1.default;
|
|
67
57
|
}
|
|
68
58
|
/**
|
|
69
59
|
* @param imageLoader
|
|
@@ -74,10 +64,8 @@ export async function resolveImageLoader(imageLoader) {
|
|
|
74
64
|
if (typeof imageLoader === "function") {
|
|
75
65
|
return imageLoader();
|
|
76
66
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
return m_1.default;
|
|
80
|
-
}
|
|
67
|
+
const m_1 = await import("../overrides/imageLoader/s3.js");
|
|
68
|
+
return m_1.default;
|
|
81
69
|
}
|
|
82
70
|
/**
|
|
83
71
|
* @returns
|
|
@@ -87,10 +75,8 @@ export async function resolveOriginResolver(originResolver) {
|
|
|
87
75
|
if (typeof originResolver === "function") {
|
|
88
76
|
return originResolver();
|
|
89
77
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
return m_1.default;
|
|
93
|
-
}
|
|
78
|
+
const m_1 = await import("../overrides/originResolver/pattern-env.js");
|
|
79
|
+
return m_1.default;
|
|
94
80
|
}
|
|
95
81
|
/**
|
|
96
82
|
* @__PURE__
|
|
@@ -99,8 +85,16 @@ export async function resolveWarmerInvoke(warmer) {
|
|
|
99
85
|
if (typeof warmer === "function") {
|
|
100
86
|
return warmer();
|
|
101
87
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
88
|
+
const m_1 = await import("../overrides/warmer/aws-lambda.js");
|
|
89
|
+
return m_1.default;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* @__PURE__
|
|
93
|
+
*/
|
|
94
|
+
export async function resolveProxyRequest(proxyRequest) {
|
|
95
|
+
if (typeof proxyRequest === "function") {
|
|
96
|
+
return proxyRequest();
|
|
105
97
|
}
|
|
98
|
+
const m_1 = await import("../overrides/proxyExternalRequest/node.js");
|
|
99
|
+
return m_1.default;
|
|
106
100
|
}
|
|
@@ -31,7 +31,7 @@ async function computeCacheControl(path, body, host, revalidate, lastModified) {
|
|
|
31
31
|
etag,
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
|
-
|
|
34
|
+
if (finalRevalidate !== CACHE_ONE_YEAR) {
|
|
35
35
|
const sMaxAge = Math.max(finalRevalidate - age, 1);
|
|
36
36
|
debug("sMaxAge", {
|
|
37
37
|
finalRevalidate,
|
|
@@ -58,13 +58,11 @@ async function computeCacheControl(path, body, host, revalidate, lastModified) {
|
|
|
58
58
|
etag,
|
|
59
59
|
};
|
|
60
60
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
};
|
|
67
|
-
}
|
|
61
|
+
return {
|
|
62
|
+
"cache-control": `s-maxage=${CACHE_ONE_YEAR}, stale-while-revalidate=${CACHE_ONE_MONTH}`,
|
|
63
|
+
"x-opennext-cache": "HIT",
|
|
64
|
+
etag,
|
|
65
|
+
};
|
|
68
66
|
}
|
|
69
67
|
async function generateResult(event, localizedPath, cachedValue, lastModified) {
|
|
70
68
|
debug("Returning result from experimental cache");
|
|
@@ -73,19 +71,19 @@ async function generateResult(event, localizedPath, cachedValue, lastModified) {
|
|
|
73
71
|
let isDataRequest = false;
|
|
74
72
|
switch (cachedValue.type) {
|
|
75
73
|
case "app":
|
|
76
|
-
isDataRequest = Boolean(event.headers
|
|
74
|
+
isDataRequest = Boolean(event.headers.rsc);
|
|
77
75
|
body = isDataRequest ? cachedValue.rsc : cachedValue.html;
|
|
78
76
|
type = isDataRequest ? "text/x-component" : "text/html; charset=utf-8";
|
|
79
77
|
break;
|
|
80
78
|
case "page":
|
|
81
|
-
isDataRequest = Boolean(event.query
|
|
79
|
+
isDataRequest = Boolean(event.query.__nextDataReq);
|
|
82
80
|
body = isDataRequest
|
|
83
81
|
? JSON.stringify(cachedValue.json)
|
|
84
82
|
: cachedValue.html;
|
|
85
83
|
type = isDataRequest ? "application/json" : "text/html; charset=utf-8";
|
|
86
84
|
break;
|
|
87
85
|
}
|
|
88
|
-
const cacheControl = await computeCacheControl(localizedPath, body, event.headers
|
|
86
|
+
const cacheControl = await computeCacheControl(localizedPath, body, event.headers.host, cachedValue.revalidate, lastModified);
|
|
89
87
|
return {
|
|
90
88
|
type: "core",
|
|
91
89
|
statusCode: 200,
|
|
@@ -130,12 +128,12 @@ export async function cacheInterceptor(event) {
|
|
|
130
128
|
return event;
|
|
131
129
|
}
|
|
132
130
|
}
|
|
133
|
-
const host = event.headers
|
|
131
|
+
const host = event.headers.host;
|
|
134
132
|
switch (cachedData.value?.type) {
|
|
135
133
|
case "app":
|
|
136
134
|
case "page":
|
|
137
135
|
return generateResult(event, localizedPath, cachedData.value, cachedData.lastModified);
|
|
138
|
-
case "redirect":
|
|
136
|
+
case "redirect": {
|
|
139
137
|
const cacheControl = await computeCacheControl(localizedPath, "", host, cachedData.value.revalidate, cachedData.lastModified);
|
|
140
138
|
return {
|
|
141
139
|
type: "core",
|
|
@@ -148,6 +146,7 @@ export async function cacheInterceptor(event) {
|
|
|
148
146
|
},
|
|
149
147
|
isBase64Encoded: false,
|
|
150
148
|
};
|
|
149
|
+
}
|
|
151
150
|
default:
|
|
152
151
|
return event;
|
|
153
152
|
}
|
|
@@ -11,6 +11,7 @@ function parse(raw, preferences, options) {
|
|
|
11
11
|
lowers.set(lower, { orig: preference, pos: pos++ });
|
|
12
12
|
if (options.prefixMatch) {
|
|
13
13
|
const parts = lower.split("-");
|
|
14
|
+
// biome-ignore lint/style/noCommaOperator:
|
|
14
15
|
while ((parts.pop(), parts.length > 0)) {
|
|
15
16
|
const joined = parts.join("-");
|
|
16
17
|
if (!lowers.has(joined)) {
|
|
@@ -32,7 +33,7 @@ function parse(raw, preferences, options) {
|
|
|
32
33
|
if (params.length > 2) {
|
|
33
34
|
throw new Error(`Invalid ${options.type} header`);
|
|
34
35
|
}
|
|
35
|
-
|
|
36
|
+
const token = params[0].toLowerCase();
|
|
36
37
|
if (!token) {
|
|
37
38
|
throw new Error(`Invalid ${options.type} header`);
|
|
38
39
|
}
|
|
@@ -47,7 +48,7 @@ function parse(raw, preferences, options) {
|
|
|
47
48
|
if (!value || (key !== "q" && key !== "Q")) {
|
|
48
49
|
throw new Error(`Invalid ${options.type} header`);
|
|
49
50
|
}
|
|
50
|
-
const score = parseFloat(value);
|
|
51
|
+
const score = Number.parseFloat(value);
|
|
51
52
|
if (score === 0) {
|
|
52
53
|
continue;
|
|
53
54
|
}
|
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
1
|
import type { Header, PrerenderManifest, RedirectDefinition, RewriteDefinition } from "../../types/next-types";
|
|
4
2
|
import type { InternalEvent, InternalResult } from "../../types/open-next";
|
|
5
|
-
export declare function
|
|
3
|
+
export declare function getNextConfigHeaders(event: InternalEvent, configHeaders?: Header[] | undefined): Record<string, string | undefined>;
|
|
6
4
|
export declare function handleRewrites<T extends RewriteDefinition>(event: InternalEvent, rewrites: T[]): {
|
|
7
5
|
internalEvent: {
|
|
8
6
|
rawPath: string;
|
|
9
7
|
url: string;
|
|
10
8
|
method: string;
|
|
11
|
-
body?: Buffer
|
|
9
|
+
body?: Buffer;
|
|
12
10
|
headers: Record<string, string>;
|
|
13
11
|
query: Record<string, string | string[]>;
|
|
14
12
|
cookies: Record<string, string>;
|
|
@@ -59,30 +59,22 @@ const computeParamHas = (headers, cookies, query) => (has) => {
|
|
|
59
59
|
}
|
|
60
60
|
};
|
|
61
61
|
function convertMatch(match, toDestination, destination) {
|
|
62
|
-
if (match) {
|
|
63
|
-
const { params } = match;
|
|
64
|
-
const isUsingParams = Object.keys(params).length > 0;
|
|
65
|
-
if (isUsingParams) {
|
|
66
|
-
return toDestination(params);
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
return destination;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
62
|
+
if (!match) {
|
|
73
63
|
return destination;
|
|
74
64
|
}
|
|
65
|
+
const { params } = match;
|
|
66
|
+
const isUsingParams = Object.keys(params).length > 0;
|
|
67
|
+
return isUsingParams ? toDestination(params) : destination;
|
|
75
68
|
}
|
|
76
|
-
export function
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
const
|
|
81
|
-
const matcher = routeHasMatcher(headers, cookies, query);
|
|
69
|
+
export function getNextConfigHeaders(event, configHeaders) {
|
|
70
|
+
if (!configHeaders) {
|
|
71
|
+
return {};
|
|
72
|
+
}
|
|
73
|
+
const matcher = routeHasMatcher(event.headers, event.cookies, event.query);
|
|
82
74
|
const requestHeaders = {};
|
|
83
75
|
const localizedRawPath = localizePath(event);
|
|
84
76
|
for (const { headers, has, missing, regex, source, locale, } of configHeaders) {
|
|
85
|
-
const path = locale === false ? rawPath : localizedRawPath;
|
|
77
|
+
const path = locale === false ? event.rawPath : localizedRawPath;
|
|
86
78
|
if (new RegExp(regex).test(path) &&
|
|
87
79
|
checkHas(matcher, has) &&
|
|
88
80
|
checkHas(matcher, missing, true)) {
|
|
@@ -95,7 +87,7 @@ export function addNextConfigHeaders(event, configHeaders) {
|
|
|
95
87
|
requestHeaders[key] = value;
|
|
96
88
|
}
|
|
97
89
|
catch {
|
|
98
|
-
debug(
|
|
90
|
+
debug(`Error matching header ${h.key} with value ${h.value}`);
|
|
99
91
|
requestHeaders[h.key] = h.value;
|
|
100
92
|
}
|
|
101
93
|
});
|
|
@@ -122,24 +114,30 @@ export function handleRewrites(event, rewrites) {
|
|
|
122
114
|
const { pathname, protocol, hostname, queryString } = getUrlParts(rewrite.destination, isExternalRewrite);
|
|
123
115
|
// We need to use a localized path if the rewrite is not locale specific
|
|
124
116
|
const pathToUse = rewrite.locale === false ? rawPath : localizedRawPath;
|
|
117
|
+
// We need to encode the "+" character with its UTF-8 equivalent "%20" to avoid 2 issues:
|
|
118
|
+
// 1. The compile function from path-to-regexp will throw an error if it finds a "+" character.
|
|
119
|
+
// https://github.com/pillarjs/path-to-regexp?tab=readme-ov-file#unexpected--or-
|
|
120
|
+
// 2. The convertToQueryString function will replace the "+" character with %2B instead of %20.
|
|
121
|
+
// %2B does not get interpreted as a space in the URL thus breaking the query string.
|
|
122
|
+
const encodePlusQueryString = queryString.replaceAll("+", "%20");
|
|
125
123
|
debug("urlParts", { pathname, protocol, hostname, queryString });
|
|
126
124
|
const toDestinationPath = compile(escapeRegex(pathname ?? "") ?? "");
|
|
127
125
|
const toDestinationHost = compile(escapeRegex(hostname ?? "") ?? "");
|
|
128
|
-
const toDestinationQuery = compile(escapeRegex(
|
|
129
|
-
|
|
126
|
+
const toDestinationQuery = compile(escapeRegex(encodePlusQueryString ?? "") ?? "");
|
|
127
|
+
const params = {
|
|
130
128
|
// params for the source
|
|
131
129
|
...getParamsFromSource(match(escapeRegex(rewrite?.source) ?? ""))(pathToUse),
|
|
132
130
|
// params for the has
|
|
133
131
|
...rewrite.has?.reduce((acc, cur) => {
|
|
134
|
-
return
|
|
132
|
+
return Object.assign(acc, computeHas(cur));
|
|
135
133
|
}, {}),
|
|
136
134
|
// params for the missing
|
|
137
135
|
...rewrite.missing?.reduce((acc, cur) => {
|
|
138
|
-
return
|
|
136
|
+
return Object.assign(acc, computeHas(cur));
|
|
139
137
|
}, {}),
|
|
140
138
|
};
|
|
141
139
|
const isUsingParams = Object.keys(params).length > 0;
|
|
142
|
-
let rewrittenQuery =
|
|
140
|
+
let rewrittenQuery = encodePlusQueryString;
|
|
143
141
|
let rewrittenHost = hostname;
|
|
144
142
|
let rewrittenPath = pathname;
|
|
145
143
|
if (isUsingParams) {
|
|
@@ -149,7 +147,7 @@ export function handleRewrites(event, rewrites) {
|
|
|
149
147
|
}
|
|
150
148
|
rewrittenUrl = isExternalRewrite
|
|
151
149
|
? `${protocol}//${rewrittenHost}${rewrittenPath}`
|
|
152
|
-
:
|
|
150
|
+
: `${rewrittenPath}`;
|
|
153
151
|
// Should we merge the query params or use only the ones from the rewrite?
|
|
154
152
|
finalQuery = {
|
|
155
153
|
...query,
|
|
@@ -194,7 +192,7 @@ function handleTrailingSlashRedirect(event) {
|
|
|
194
192
|
};
|
|
195
193
|
// eslint-disable-next-line sonarjs/elseif-without-else
|
|
196
194
|
}
|
|
197
|
-
|
|
195
|
+
if (!NextConfig.trailingSlash &&
|
|
198
196
|
event.rawPath.endsWith("/") &&
|
|
199
197
|
event.rawPath !== "/") {
|
|
200
198
|
const headersLocation = event.url.split("?");
|
|
@@ -208,8 +206,7 @@ function handleTrailingSlashRedirect(event) {
|
|
|
208
206
|
isBase64Encoded: false,
|
|
209
207
|
};
|
|
210
208
|
}
|
|
211
|
-
|
|
212
|
-
return false;
|
|
209
|
+
return false;
|
|
213
210
|
}
|
|
214
211
|
export function handleRedirects(event, redirects) {
|
|
215
212
|
const trailingSlashRedirect = handleTrailingSlashRedirect(event);
|
|
@@ -244,8 +241,9 @@ export function fixDataPage(internalEvent, buildId) {
|
|
|
244
241
|
};
|
|
245
242
|
}
|
|
246
243
|
if (rawPath.startsWith(dataPattern) && rawPath.endsWith(".json")) {
|
|
247
|
-
|
|
248
|
-
|
|
244
|
+
const newPath = rawPath
|
|
245
|
+
.slice(dataPattern.length, -".json".length)
|
|
246
|
+
.replace(/^\/index$/, "/");
|
|
249
247
|
query.__nextDataReq = "1";
|
|
250
248
|
return {
|
|
251
249
|
...internalEvent,
|
|
@@ -266,7 +264,7 @@ export function handleFallbackFalse(internalEvent, prerenderManifest) {
|
|
|
266
264
|
return routeRegexExp.test(rawPath);
|
|
267
265
|
});
|
|
268
266
|
const locales = NextConfig.i18n?.locales;
|
|
269
|
-
const routesAlreadyHaveLocale =
|
|
267
|
+
const routesAlreadyHaveLocale = locales?.includes(rawPath.split("/")[1]) ||
|
|
270
268
|
// If we don't use locales, we don't need to add the default locale
|
|
271
269
|
locales === undefined;
|
|
272
270
|
const localizedPath = routesAlreadyHaveLocale
|
|
@@ -21,32 +21,36 @@ function defaultMiddlewareLoader() {
|
|
|
21
21
|
// @returns undefined | res.end()
|
|
22
22
|
// if res.end() is return, the parent needs to return and not process next server
|
|
23
23
|
export async function handleMiddleware(internalEvent, middlewareLoader = defaultMiddlewareLoader) {
|
|
24
|
-
const
|
|
25
|
-
|
|
24
|
+
const headers = internalEvent.headers;
|
|
25
|
+
// We bypass the middleware if the request is internal
|
|
26
|
+
if (headers["x-isr"])
|
|
27
|
+
return internalEvent;
|
|
26
28
|
// We only need the normalizedPath to check if the middleware should run
|
|
29
|
+
const normalizedPath = localizePath(internalEvent);
|
|
27
30
|
const hasMatch = middleMatch.some((r) => r.test(normalizedPath));
|
|
28
31
|
if (!hasMatch)
|
|
29
32
|
return internalEvent;
|
|
30
|
-
//
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
|
|
33
|
+
// Retrieve the protocol:
|
|
34
|
+
// - In lambda, the url only contains the rawPath and the query - default to https
|
|
35
|
+
// - In cloudflare, the protocol is usually http in dev and https in production
|
|
36
|
+
const protocol = internalEvent.url.startsWith("http://") ? "http:" : "https:";
|
|
37
|
+
const host = headers.host
|
|
38
|
+
? `${protocol}//${headers.host}`
|
|
35
39
|
: "http://localhost:3000";
|
|
36
40
|
const initialUrl = new URL(normalizedPath, host);
|
|
37
|
-
initialUrl.search = convertToQueryString(query);
|
|
41
|
+
initialUrl.search = convertToQueryString(internalEvent.query);
|
|
38
42
|
const url = initialUrl.toString();
|
|
39
|
-
// console.log("url", url, normalizedPath);
|
|
40
43
|
const middleware = await middlewareLoader();
|
|
41
44
|
const result = await middleware.default({
|
|
45
|
+
// `geo` is pre Next 15.
|
|
42
46
|
geo: {
|
|
43
|
-
city:
|
|
44
|
-
country:
|
|
45
|
-
region:
|
|
46
|
-
latitude:
|
|
47
|
-
longitude:
|
|
47
|
+
city: headers["x-open-next-city"],
|
|
48
|
+
country: headers["x-open-next-country"],
|
|
49
|
+
region: headers["x-open-next-region"],
|
|
50
|
+
latitude: headers["x-open-next-latitude"],
|
|
51
|
+
longitude: headers["x-open-next-longitude"],
|
|
48
52
|
},
|
|
49
|
-
headers
|
|
53
|
+
headers,
|
|
50
54
|
method: internalEvent.method || "GET",
|
|
51
55
|
nextConfig: {
|
|
52
56
|
basePath: NextConfig.basePath,
|
|
@@ -96,7 +100,7 @@ export async function handleMiddleware(internalEvent, middlewareLoader = default
|
|
|
96
100
|
resHeaders.location =
|
|
97
101
|
responseHeaders
|
|
98
102
|
.get("location")
|
|
99
|
-
?.replace("http://localhost:3000",
|
|
103
|
+
?.replace("http://localhost:3000", `${protocol}//${internalEvent.headers.host}`) ?? resHeaders.location;
|
|
100
104
|
// res.setHeader("Location", location);
|
|
101
105
|
return {
|
|
102
106
|
body: emptyReadableStream(),
|
|
@@ -124,9 +128,9 @@ export async function handleMiddleware(internalEvent, middlewareLoader = default
|
|
|
124
128
|
const rewriteUrlObject = new URL(rewriteUrl);
|
|
125
129
|
newUrl = rewriteUrlObject.pathname;
|
|
126
130
|
// Reset the query params if the middleware is a rewrite
|
|
127
|
-
if (middlewareQueryString
|
|
131
|
+
if (middlewareQueryString.__nextDataReq) {
|
|
128
132
|
middlewareQueryString = {
|
|
129
|
-
__nextDataReq: middlewareQueryString
|
|
133
|
+
__nextDataReq: middlewareQueryString.__nextDataReq,
|
|
130
134
|
};
|
|
131
135
|
}
|
|
132
136
|
else {
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
|
-
/// <reference types="node" />
|
|
4
1
|
import type { OutgoingHttpHeaders } from "node:http";
|
|
5
2
|
import type { IncomingMessage, StreamCreator } from "../../http/index.js";
|
|
6
3
|
import { OpenNextNodeResponse } from "../../http/openNextResponse.js";
|
|
@@ -59,16 +56,6 @@ export declare function unescapeRegex(str: string): string;
|
|
|
59
56
|
* @__PURE__
|
|
60
57
|
*/
|
|
61
58
|
export declare function convertBodyToReadableStream(method: string, body?: string | Buffer): ReadableStream<any> | undefined;
|
|
62
|
-
/**
|
|
63
|
-
*
|
|
64
|
-
* @__PURE__
|
|
65
|
-
*/
|
|
66
|
-
export declare function proxyRequest(internalEvent: InternalEvent, res: OpenNextNodeResponse): Promise<void>;
|
|
67
|
-
declare global {
|
|
68
|
-
var openNextDebug: boolean;
|
|
69
|
-
var openNextVersion: string;
|
|
70
|
-
var lastModified: Record<string, number>;
|
|
71
|
-
}
|
|
72
59
|
/**
|
|
73
60
|
*
|
|
74
61
|
* @__PURE__
|