@opennextjs/aws 3.2.1 → 3.3.0
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 +21 -2
- package/dist/adapters/cache.d.ts +0 -23
- package/dist/adapters/cache.js +10 -12
- 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.d.ts +1 -2
- package/dist/adapters/image-optimization-adapter.js +4 -4
- package/dist/adapters/logger.d.ts +0 -3
- package/dist/adapters/logger.js +32 -13
- package/dist/adapters/middleware.js +42 -18
- package/dist/adapters/plugins/image-optimization/image-optimization.d.ts +1 -3
- package/dist/adapters/plugins/image-optimization/image-optimization.js +0 -1
- package/dist/adapters/plugins/image-optimization/image-optimization.replacement.d.ts +1 -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 +1 -1
- package/dist/build/copyTracedFiles.js +15 -26
- package/dist/build/createAssets.js +36 -27
- package/dist/build/createImageOptimizationBundle.js +1 -1
- package/dist/build/createMiddleware.js +8 -3
- package/dist/build/createRevalidationBundle.js +1 -1
- package/dist/build/createServerBundle.js +25 -31
- package/dist/build/createWarmerBundle.js +1 -1
- package/dist/build/edge/createEdgeBundle.d.ts +8 -4
- package/dist/build/edge/createEdgeBundle.js +34 -16
- package/dist/build/generateOutput.js +7 -13
- package/dist/build/helper.d.ts +28 -5
- package/dist/build/helper.js +44 -15
- package/dist/build/installDeps.js +1 -1
- package/dist/build/patch/patchedAsyncStorage.js +1 -1
- package/dist/build/utils.js +3 -2
- package/dist/build/validateConfig.js +4 -1
- package/dist/core/createGenericHandler.d.ts +2 -4
- package/dist/core/createGenericHandler.js +1 -2
- package/dist/core/createMainHandler.d.ts +0 -17
- package/dist/core/createMainHandler.js +5 -4
- package/dist/core/edgeFunctionHandler.d.ts +1 -51
- package/dist/core/patchAsyncStorage.js +5 -6
- package/dist/core/requestHandler.d.ts +1 -2
- package/dist/core/requestHandler.js +99 -90
- 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 +18 -27
- package/dist/core/routing/middleware.d.ts +3 -3
- package/dist/core/routing/middleware.js +20 -20
- package/dist/core/routing/util.d.ts +2 -15
- package/dist/core/routing/util.js +26 -88
- package/dist/core/routingHandler.d.ts +4 -8
- package/dist/core/routingHandler.js +36 -18
- package/dist/core/util.js +5 -3
- package/dist/helpers/withCloudflare.d.ts +1 -1
- package/dist/helpers/withCloudflare.js +2 -2
- package/dist/helpers/withSST.d.ts +1 -1
- package/dist/http/openNextResponse.d.ts +6 -18
- package/dist/http/openNextResponse.js +32 -32
- 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 +8 -8
- 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 +3 -5
- package/dist/overrides/converters/edge.js +15 -18
- 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/dummy.js +4 -3
- 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 +8 -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/dummy.js +2 -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/warmer/dummy.js +2 -1
- package/dist/overrides/wrappers/aws-lambda-streaming.d.ts +3 -3
- package/dist/overrides/wrappers/aws-lambda-streaming.js +0 -4
- package/dist/overrides/wrappers/aws-lambda.d.ts +2 -2
- package/dist/overrides/wrappers/aws-lambda.js +0 -3
- package/dist/overrides/wrappers/cloudflare-edge.d.ts +9 -0
- package/dist/overrides/wrappers/cloudflare-edge.js +38 -0
- package/dist/overrides/wrappers/cloudflare-node.d.ts +8 -0
- package/dist/overrides/wrappers/cloudflare-node.js +47 -0
- package/dist/overrides/wrappers/dummy.d.ts +3 -3
- package/dist/overrides/wrappers/dummy.js +1 -1
- package/dist/overrides/wrappers/node.d.ts +3 -3
- package/dist/overrides/wrappers/node.js +3 -6
- package/dist/plugins/edge.js +6 -5
- package/dist/plugins/replacement.js +2 -2
- package/dist/plugins/resolve.d.ts +3 -1
- package/dist/plugins/resolve.js +9 -2
- 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 +33 -41
- package/dist/types/overrides.d.ts +86 -0
- package/dist/{adapters → utils}/binary.js +1 -0
- package/dist/utils/error.d.ts +1 -0
- package/dist/utils/error.js +8 -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 +3 -3
- 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/wrappers/cloudflare.d.ts +0 -11
- package/dist/overrides/wrappers/cloudflare.js +0 -20
- /package/dist/{overrides/incrementalCache/types.js → types/global.js} +0 -0
- /package/dist/{overrides/queue/types.js → types/overrides.js} +0 -0
- /package/dist/{adapters → utils}/binary.d.ts +0 -0
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
|
});
|
|
@@ -132,16 +124,16 @@ export function handleRewrites(event, rewrites) {
|
|
|
132
124
|
const toDestinationPath = compile(escapeRegex(pathname ?? "") ?? "");
|
|
133
125
|
const toDestinationHost = compile(escapeRegex(hostname ?? "") ?? "");
|
|
134
126
|
const toDestinationQuery = compile(escapeRegex(encodePlusQueryString ?? "") ?? "");
|
|
135
|
-
|
|
127
|
+
const params = {
|
|
136
128
|
// params for the source
|
|
137
129
|
...getParamsFromSource(match(escapeRegex(rewrite?.source) ?? ""))(pathToUse),
|
|
138
130
|
// params for the has
|
|
139
131
|
...rewrite.has?.reduce((acc, cur) => {
|
|
140
|
-
return
|
|
132
|
+
return Object.assign(acc, computeHas(cur));
|
|
141
133
|
}, {}),
|
|
142
134
|
// params for the missing
|
|
143
135
|
...rewrite.missing?.reduce((acc, cur) => {
|
|
144
|
-
return
|
|
136
|
+
return Object.assign(acc, computeHas(cur));
|
|
145
137
|
}, {}),
|
|
146
138
|
};
|
|
147
139
|
const isUsingParams = Object.keys(params).length > 0;
|
|
@@ -200,7 +192,7 @@ function handleTrailingSlashRedirect(event) {
|
|
|
200
192
|
};
|
|
201
193
|
// eslint-disable-next-line sonarjs/elseif-without-else
|
|
202
194
|
}
|
|
203
|
-
|
|
195
|
+
if (!NextConfig.trailingSlash &&
|
|
204
196
|
event.rawPath.endsWith("/") &&
|
|
205
197
|
event.rawPath !== "/") {
|
|
206
198
|
const headersLocation = event.url.split("?");
|
|
@@ -214,8 +206,7 @@ function handleTrailingSlashRedirect(event) {
|
|
|
214
206
|
isBase64Encoded: false,
|
|
215
207
|
};
|
|
216
208
|
}
|
|
217
|
-
|
|
218
|
-
return false;
|
|
209
|
+
return false;
|
|
219
210
|
}
|
|
220
211
|
export function handleRedirects(event, redirects) {
|
|
221
212
|
const trailingSlashRedirect = handleTrailingSlashRedirect(event);
|
|
@@ -236,7 +227,7 @@ export function handleRedirects(event, redirects) {
|
|
|
236
227
|
}
|
|
237
228
|
export function fixDataPage(internalEvent, buildId) {
|
|
238
229
|
const { rawPath, query } = internalEvent;
|
|
239
|
-
const dataPattern =
|
|
230
|
+
const dataPattern = `${NextConfig.basePath ?? ""}/_next/data/${buildId}`;
|
|
240
231
|
// Return 404 for data requests that don't match the buildId
|
|
241
232
|
if (rawPath.startsWith("/_next/data") && !rawPath.startsWith(dataPattern)) {
|
|
242
233
|
return {
|
|
@@ -273,7 +264,7 @@ export function handleFallbackFalse(internalEvent, prerenderManifest) {
|
|
|
273
264
|
return routeRegexExp.test(rawPath);
|
|
274
265
|
});
|
|
275
266
|
const locales = NextConfig.i18n?.locales;
|
|
276
|
-
const routesAlreadyHaveLocale =
|
|
267
|
+
const routesAlreadyHaveLocale = locales?.includes(rawPath.split("/")[1]) ||
|
|
277
268
|
// If we don't use locales, we don't need to add the default locale
|
|
278
269
|
locales === undefined;
|
|
279
270
|
const localizedPath = routesAlreadyHaveLocale
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { InternalEvent, InternalResult } from "../../types/open-next.js";
|
|
2
|
-
type
|
|
2
|
+
type MiddlewareEvent = InternalEvent & {
|
|
3
3
|
responseHeaders?: Record<string, string | string[]>;
|
|
4
|
-
|
|
4
|
+
isExternalRewrite?: boolean;
|
|
5
5
|
};
|
|
6
6
|
type Middleware = (request: Request) => Response | Promise<Response>;
|
|
7
7
|
type MiddlewareLoader = () => Promise<{
|
|
8
8
|
default: Middleware;
|
|
9
9
|
}>;
|
|
10
|
-
export declare function handleMiddleware(internalEvent: InternalEvent, middlewareLoader?: MiddlewareLoader): Promise<
|
|
10
|
+
export declare function handleMiddleware(internalEvent: InternalEvent, middlewareLoader?: MiddlewareLoader): Promise<MiddlewareEvent | InternalResult>;
|
|
11
11
|
export {};
|
|
@@ -21,35 +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
|
-
// We bypass the middleware if the request is internal
|
|
31
|
-
if (internalEvent.headers["x-isr"])
|
|
32
|
-
return internalEvent;
|
|
33
33
|
// Retrieve the protocol:
|
|
34
34
|
// - In lambda, the url only contains the rawPath and the query - default to https
|
|
35
35
|
// - In cloudflare, the protocol is usually http in dev and https in production
|
|
36
36
|
const protocol = internalEvent.url.startsWith("http://") ? "http:" : "https:";
|
|
37
|
-
const host =
|
|
38
|
-
? `${protocol}//${
|
|
37
|
+
const host = headers.host
|
|
38
|
+
? `${protocol}//${headers.host}`
|
|
39
39
|
: "http://localhost:3000";
|
|
40
40
|
const initialUrl = new URL(normalizedPath, host);
|
|
41
|
-
initialUrl.search = convertToQueryString(query);
|
|
41
|
+
initialUrl.search = convertToQueryString(internalEvent.query);
|
|
42
42
|
const url = initialUrl.toString();
|
|
43
43
|
const middleware = await middlewareLoader();
|
|
44
44
|
const result = await middleware.default({
|
|
45
|
+
// `geo` is pre Next 15.
|
|
45
46
|
geo: {
|
|
46
|
-
city:
|
|
47
|
-
country:
|
|
48
|
-
region:
|
|
49
|
-
latitude:
|
|
50
|
-
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"],
|
|
51
52
|
},
|
|
52
|
-
headers
|
|
53
|
+
headers,
|
|
53
54
|
method: internalEvent.method || "GET",
|
|
54
55
|
nextConfig: {
|
|
55
56
|
basePath: NextConfig.basePath,
|
|
@@ -113,7 +114,7 @@ export async function handleMiddleware(internalEvent, middlewareLoader = default
|
|
|
113
114
|
// NOTE: the header was added to `req` from above
|
|
114
115
|
const rewriteUrl = responseHeaders.get("x-middleware-rewrite");
|
|
115
116
|
let rewritten = false;
|
|
116
|
-
let
|
|
117
|
+
let isExternalRewrite = false;
|
|
117
118
|
let middlewareQueryString = internalEvent.query;
|
|
118
119
|
let newUrl = internalEvent.url;
|
|
119
120
|
if (rewriteUrl) {
|
|
@@ -121,15 +122,15 @@ export async function handleMiddleware(internalEvent, middlewareLoader = default
|
|
|
121
122
|
if (isExternal(rewriteUrl, internalEvent.headers.host)) {
|
|
122
123
|
newUrl = rewriteUrl;
|
|
123
124
|
rewritten = true;
|
|
124
|
-
|
|
125
|
+
isExternalRewrite = true;
|
|
125
126
|
}
|
|
126
127
|
else {
|
|
127
128
|
const rewriteUrlObject = new URL(rewriteUrl);
|
|
128
129
|
newUrl = rewriteUrlObject.pathname;
|
|
129
130
|
// Reset the query params if the middleware is a rewrite
|
|
130
|
-
if (middlewareQueryString
|
|
131
|
+
if (middlewareQueryString.__nextDataReq) {
|
|
131
132
|
middlewareQueryString = {
|
|
132
|
-
__nextDataReq: middlewareQueryString
|
|
133
|
+
__nextDataReq: middlewareQueryString.__nextDataReq,
|
|
133
134
|
};
|
|
134
135
|
}
|
|
135
136
|
else {
|
|
@@ -146,7 +147,6 @@ export async function handleMiddleware(internalEvent, middlewareLoader = default
|
|
|
146
147
|
if (result.body) {
|
|
147
148
|
// transfer response body to res
|
|
148
149
|
const body = result.body;
|
|
149
|
-
// await pipeReadable(result.response.body, res);
|
|
150
150
|
return {
|
|
151
151
|
type: internalEvent.type,
|
|
152
152
|
statusCode: statusCode,
|
|
@@ -168,6 +168,6 @@ export async function handleMiddleware(internalEvent, middlewareLoader = default
|
|
|
168
168
|
query: middlewareQueryString,
|
|
169
169
|
cookies: internalEvent.cookies,
|
|
170
170
|
remoteAddress: internalEvent.remoteAddress,
|
|
171
|
-
|
|
171
|
+
isExternalRewrite,
|
|
172
172
|
};
|
|
173
173
|
}
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
|
-
/// <reference types="node" />
|
|
4
1
|
import type { OutgoingHttpHeaders } from "node:http";
|
|
5
|
-
import type { IncomingMessage
|
|
2
|
+
import type { IncomingMessage } from "../../http/index.js";
|
|
6
3
|
import { OpenNextNodeResponse } from "../../http/openNextResponse.js";
|
|
7
4
|
import type { MiddlewareManifest } from "../../types/next-types";
|
|
8
|
-
import type { InternalEvent, InternalResult } from "../../types/open-next.js";
|
|
5
|
+
import type { InternalEvent, InternalResult, StreamCreator } from "../../types/open-next.js";
|
|
9
6
|
/**
|
|
10
7
|
*
|
|
11
8
|
* @__PURE__
|
|
@@ -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__
|