-
Notifications
You must be signed in to change notification settings - Fork 27.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update app route handler proxy handling (#47088)
This ensures our Proxy wrapping request fields works properly in the edge-runtime by explicitly binding to the correct request instance. x-ref: [slack thread](https://vercel.slack.com/archives/C03UR7US95F/p1678730563467089?thread_ts=1678662292.695769&cid=C03UR7US95F)
- Loading branch information
Showing
6 changed files
with
150 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
test/e2e/app-dir/app-routes/app/edge/advanced/body/json/route.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import type { NextRequest } from 'next/server' | ||
import { withRequestMeta } from '../../../../../helpers' | ||
|
||
export const runtime = 'experimental-edge' | ||
|
||
export async function POST(request: NextRequest) { | ||
const body = await request.json() | ||
return new Response('hello, world', { | ||
status: 200, | ||
headers: withRequestMeta({ body }), | ||
}) | ||
} |
27 changes: 27 additions & 0 deletions
27
test/e2e/app-dir/app-routes/app/edge/advanced/body/streaming/route.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import type { NextRequest } from 'next/server' | ||
|
||
export const runtime = 'experimental-edge' | ||
|
||
export async function POST(request: NextRequest) { | ||
const reader = request.body?.getReader() | ||
if (!reader) { | ||
return new Response(null, { status: 400, statusText: 'Bad Request' }) | ||
} | ||
|
||
// Readable stream here is polyfilled from the Fetch API (from undici). | ||
const stream = new ReadableStream({ | ||
async pull(controller) { | ||
// Read the next chunk from the stream. | ||
const { value, done } = await reader.read() | ||
if (done) { | ||
// Finish the stream. | ||
return controller.close() | ||
} | ||
|
||
// Add the request value to the response stream. | ||
controller.enqueue(value) | ||
}, | ||
}) | ||
|
||
return new Response(stream, { status: 200 }) | ||
} |
12 changes: 12 additions & 0 deletions
12
test/e2e/app-dir/app-routes/app/edge/advanced/body/text/route.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import type { NextRequest } from 'next/server' | ||
import { withRequestMeta } from '../../../../../helpers' | ||
|
||
export const runtime = 'experimental-edge' | ||
|
||
export async function POST(request: NextRequest) { | ||
const body = await request.text() | ||
return new Response('hello, world', { | ||
status: 200, | ||
headers: withRequestMeta({ body }), | ||
}) | ||
} |
14 changes: 14 additions & 0 deletions
14
test/e2e/app-dir/app-routes/app/edge/advanced/query/route.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { withRequestMeta } from '../../../../helpers' | ||
import { NextRequest } from 'next/server' | ||
|
||
export const runtime = 'experimental-edge' | ||
|
||
export async function GET(request: NextRequest): Promise<Response> { | ||
const { searchParams } = request.nextUrl | ||
|
||
return new Response('hello, world', { | ||
headers: withRequestMeta({ | ||
ping: searchParams.get('ping'), | ||
}), | ||
}) | ||
} |