Skip to content

Commit bf40d1d

Browse files
committed
review
1 parent ba8056b commit bf40d1d

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

packages/open-next/src/core/routing/cacheInterceptor.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { createHash } from "node:crypto";
22

33
import { NextConfig, PrerenderManifest } from "config/index";
4-
import type { InternalEvent, InternalResult } from "types/open-next";
4+
import type {
5+
InternalEvent,
6+
InternalResult,
7+
MiddlewareEvent,
8+
} from "types/open-next";
59
import type { CacheValue } from "types/overrides";
610
import { emptyReadableStream, toReadableStream } from "utils/stream";
711

@@ -100,7 +104,7 @@ async function computeCacheControl(
100104
}
101105

102106
async function generateResult(
103-
event: InternalEvent,
107+
event: MiddlewareEvent,
104108
localizedPath: string,
105109
cachedValue: CacheValue<"cache">,
106110
lastModified?: number,
@@ -183,7 +187,7 @@ function decodePathParams(pathname: string): string {
183187
}
184188

185189
export async function cacheInterceptor(
186-
event: InternalEvent,
190+
event: MiddlewareEvent,
187191
): Promise<InternalEvent | InternalResult> {
188192
if (
189193
Boolean(event.headers["next-action"]) ||

packages/open-next/src/core/routing/middleware.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ import {
66
NextConfig,
77
PrerenderManifest,
88
} from "config/index.js";
9-
import type { InternalEvent, InternalResult } from "types/open-next.js";
9+
import type {
10+
InternalEvent,
11+
InternalResult,
12+
MiddlewareEvent,
13+
} from "types/open-next.js";
1014
import { emptyReadableStream } from "utils/stream.js";
1115

1216
import { getQueryFromSearchParams } from "../../overrides/converters/utils.js";
@@ -28,12 +32,6 @@ const middleMatch = getMiddlewareMatch(
2832

2933
const REDIRECTS = new Set([301, 302, 303, 307, 308]);
3034

31-
type MiddlewareEvent = InternalEvent & {
32-
responseHeaders?: Record<string, string | string[]>;
33-
isExternalRewrite?: boolean;
34-
rewriteStatusCode?: number;
35-
};
36-
3735
type Middleware = (request: Request) => Response | Promise<Response>;
3836
type MiddlewareLoader = () => Promise<{ default: Middleware }>;
3937

packages/open-next/src/types/open-next.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,14 @@ export type InternalEvent = {
3030
readonly query: Record<string, string | string[]>;
3131
readonly cookies: Record<string, string>;
3232
readonly remoteAddress: string;
33-
// Used for NextResponse.rewrite's status code in middleware
34-
readonly rewriteStatusCode?: number;
3533
} & BaseEventOrResult<"core">;
3634

35+
export type MiddlewareEvent = InternalEvent & {
36+
responseHeaders?: Record<string, string | string[]>;
37+
isExternalRewrite?: boolean;
38+
rewriteStatusCode?: number;
39+
};
40+
3741
export type InternalResult = {
3842
statusCode: number;
3943
headers: Record<string, string | string[]>;

0 commit comments

Comments
 (0)