Files
cloudflare__vinext/tests/fixtures/cf-app-basic/pages/api/dump-headers.ts
James Anderson 600ba69b4d fix(routing): propagate middleware draft cookie to pages/api fallback (#1520) (#1845)
* fix(routing): propagate middleware draft cookie to pages/api fallback (#1520)

In a hybrid app (app/ + pages/api/*), requests with no matching App Router
route fall through to the Pages Router via renderPagesFallback. The bridge
forwarded middleware-mutated request headers and response headers, but dropped
the __prerender_bypass Set-Cookie emitted by draftMode().enable()/disable()
inside middleware — that cookie lives in a request-scoped side channel that
App Router route handlers and page renders read via getDraftModeCookieHeader(),
but the Pages fallback path never did.

Thread getDraftModeCookieHeader through the bridge and append the draft cookie
to the Pages Router fallback response, matching how App Router responses surface
it. Closes the draft-mode flow called out in #1520.

Closes #1520

* test(routing): cover draft-cookie fallback in app-pages-bridge unit test

Add getDraftModeCookieHeader to the renderPagesFallback dependency stub and
assert the draft cookie is appended (API + renderPage branches) and omitted
when middleware did not enable draft mode. Keeps the unit test in sync with
the new required dependency.

* docs(routing): document hybrid-dev draft-mode limitation in pages bridge

Address review feedback on #1845: clarify in app-pages-bridge that the
draft-cookie fallback covers production (inline RSC handler), while hybrid dev
runs middleware in a separate Vite Pages SSR runner where draftMode() inside
middleware is not yet permitted — a pre-existing limitation tracked separately
from #1520. The unit-test regression flagged by review was already fixed in
ae5978a4.
2026-06-08 19:34:28 +01:00

11 lines
379 B
TypeScript

import type { NextApiRequest, NextApiResponse } from "next";
/**
* Echoes the request headers as JSON. Used to assert that middleware-mutated
* request headers reach a Pages Router API route in a hybrid app/ + pages/ app.
* Regression coverage for #1520.
*/
export default function handler(req: NextApiRequest, res: NextApiResponse) {
res.status(200).json(req.headers);
}