Skip to content

Commit

Permalink
chore: add bodyInit for createWebRequest (#5766)
Browse files Browse the repository at this point in the history
  • Loading branch information
yimingjfe committed May 22, 2024
1 parent f3267e0 commit 7ed2fbc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .changeset/happy-pumas-melt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@modern-js/server-core': patch
---

chore: add bodyInit for createWebRequest
chore: createWebRequest 函数支持 bodyInit 入参
9 changes: 5 additions & 4 deletions packages/server/core/src/base/adapters/node/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ installGlobals();
export const createWebRequest = (
req: NodeRequest,
res: NodeResponse,
body?: BodyInit,
): Request => {
const headerRecord: [string, string][] = [];
const len = req.rawHeaders.length;
Expand All @@ -30,12 +31,12 @@ export const createWebRequest = (
};
res.on('close', () => controller.abort());

// TODO: Since we don't want break changes and now node.req.body will be consumed in bff, custom server, render, so we don't create a stream and consume node.req here now.
// Since we don't want break changes and now node.req.body will be consumed in bff, custom server, render, so we don't create a stream and consume node.req here by default.
if (
!(method === 'GET' || method === 'HEAD') &&
req.url?.includes('__loader')
body ||
(!(method === 'GET' || method === 'HEAD') && req.url?.includes('__loader'))
) {
init.body = createReadableStreamFromReadable(req);
init.body = body ?? createReadableStreamFromReadable(req);
(init as { duplex: 'half' }).duplex = 'half';
}

Expand Down

0 comments on commit 7ed2fbc

Please sign in to comment.