Skip to content

Commit 365fba9

Browse files
committed
Content-length and fix for x-matched-path
1 parent 5b1b8cf commit 365fba9

File tree

1 file changed

+7
-4
lines changed
  • packages/@apphosting/adapter-nextjs/src/bin

1 file changed

+7
-4
lines changed

packages/@apphosting/adapter-nextjs/src/bin/serve.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,28 +310,31 @@ await grpcServer.register(fastifyConnectPlugin, {
310310
resolveResumeBuffer = new Promise<PassThrough>(async (resolve) => {
311311
const socket = new Socket();
312312
const resumeRequest = new IncomingMessage(socket);
313-
const postponed = Buffer.from(new TextDecoder().decode(postponedToken), "base64url").toString();
313+
const tokenString = new TextDecoder().decode(postponedToken);
314+
const resumeData = Buffer.from(tokenString, "base64url");
314315

315316
// We construct a new request to the Next.js server to resume the
316317
// postponed page.
317318
// This is the old way of doing PPR resumption, I'm having trouble with it in NextJS 16
318319
// TODO investigate a stable API or why this is bugging out on me
319-
const resumePath = `/_next/postponed/resume${path === "/" ? "/index" : path}`;
320+
const matchedPath = path === "/" ? "/index" : path;
321+
const resumePath = `/_next/postponed/resume${matchedPath}`;
320322
resumeRequest.url = resumePath;
321323
resumeRequest.method = "POST";
322324
resumeRequest.httpVersion = "1.1";
323325
resumeRequest.httpVersionMajor = 1;
324326
resumeRequest.httpVersionMinor = 1;
325-
resumeRequest.push(postponed.trim());
327+
resumeRequest.push(resumeData);
326328
resumeRequest.push(null);
327329

328330
for (const header of requestHeaders) {
329331
// drop HTTP2 pseudo headers
330332
if (header.key.startsWith(":")) continue;
331333
resumeRequest.headers[header.key] = getRequestHeader(header.key);
332334
}
333-
resumeRequest.headers['x-matched-path'] = resumePath;
335+
resumeRequest.headers['x-matched-path'] = matchedPath;
334336
resumeRequest.headers['next-resume'] = "1";
337+
resumeRequest.headers['content-length'] = Buffer.byteLength(resumeData).toString();
335338

336339
const resumeResponse = new ServerResponse(resumeRequest);
337340
const intermediaryStream = new PassThrough();

0 commit comments

Comments
 (0)