This commit is contained in:
JonLuca De Caro
2026-03-20 14:49:36 -07:00
parent ac4b52dbcb
commit 947683286c

View File

@@ -18,8 +18,12 @@ import {
// @ts-expect-error -- virtual module resolved by vinext at build time // @ts-expect-error -- virtual module resolved by vinext at build time
import { renderPage, handleApiRoute, runMiddleware, vinextConfig } from "virtual:vinext-server-entry"; import { renderPage, handleApiRoute, runMiddleware, vinextConfig } from "virtual:vinext-server-entry";
interface AssetFetcher {
fetch(request: Request): Promise<Response>;
}
interface Env { interface Env {
ASSETS: Fetcher; ASSETS: AssetFetcher;
IMAGES: { IMAGES: {
input(stream: ReadableStream): { input(stream: ReadableStream): {
transform(options: Record<string, unknown>): { transform(options: Record<string, unknown>): {
@@ -56,6 +60,11 @@ function stripBasePath(pathname: string, basePath: string): string {
return pathname.slice(basePath.length) || "/"; return pathname.slice(basePath.length) || "/";
} }
function stripQueryString(url: string): string {
const queryIndex = url.indexOf("?");
return queryIndex === -1 ? url : url.slice(0, queryIndex);
}
export default { export default {
async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> { async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
try { try {
@@ -207,7 +216,7 @@ export default {
// Config header matching must keep using the original normalized pathname // Config header matching must keep using the original normalized pathname
// even if middleware rewrites the downstream route/render target. // even if middleware rewrites the downstream route/render target.
let resolvedPathname = resolvedUrl.split("?")[0]; let resolvedPathname = stripQueryString(resolvedUrl);
// ── 5. Apply custom headers from next.config.js ─────────────── // ── 5. Apply custom headers from next.config.js ───────────────
// Config headers are additive for multi-value headers (Vary, // Config headers are additive for multi-value headers (Vary,
@@ -247,7 +256,7 @@ export default {
return proxyExternalRequest(request, rewritten); return proxyExternalRequest(request, rewritten);
} }
resolvedUrl = rewritten; resolvedUrl = rewritten;
resolvedPathname = rewritten.split("?")[0]; resolvedPathname = stripQueryString(rewritten);
} }
} }
@@ -267,7 +276,7 @@ export default {
return proxyExternalRequest(request, rewritten); return proxyExternalRequest(request, rewritten);
} }
resolvedUrl = rewritten; resolvedUrl = rewritten;
resolvedPathname = rewritten.split("?")[0]; resolvedPathname = stripQueryString(rewritten);
} }
} }