Skip to content

Commit

Permalink
fix(src): replace request spread with explicit options
Browse files Browse the repository at this point in the history
closes #1011
addresses #983
  • Loading branch information
Xunnamius committed Mar 3, 2024
1 parent ca4721f commit 633a046
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,21 @@ export async function testApiHandler<NextResponseJsonType = any>({
void createServerAdapter(async (request) => {
try {
assert(appHandler !== undefined);

const {
cache,
credentials,
headers,
integrity,
keepalive,
method,
mode,
redirect,
referrer,
referrerPolicy,
signal
} = request;

const rawRequest = rebindJsonMethodAsSummoner(
new NextRequest(
normalizeUrlForceTrailingSlashIfPathnameEmpty(
Expand All @@ -395,15 +410,25 @@ export async function testApiHandler<NextResponseJsonType = any>({
* See also: https://stackoverflow.com/a/57014050/1367414
*/
{
...request,
body: readableStreamOrNullFromAsyncIterable(
// ? request.body claims to be ReadableStream, but it's
// ? actually a Node.js native stream (i.e. iterable)...
request.body as unknown as AsyncIterable<any>
),
cache,
credentials,
// https://github.com/nodejs/node/issues/46221
// @ts-expect-error: TS types are not yet updated
duplex: 'half'
// @ts-expect-error: Next.js's RequestInit is lacking "duplex"
duplex: 'half',
headers,
integrity,
keepalive,
method,
mode,
redirect,
referrer,
referrerPolicy,
signal
}
)
);
Expand Down

0 comments on commit 633a046

Please sign in to comment.