mirror of
https://github.com/hanzoai/next.js.git
synced 2026-10-30 14:46:38 +00:00
This adds updated matching handle for the server to separate out the matching and executing of different route types e.g. page routes, API routes, and app routes. Co-authored-by: JJ Kasper <[email protected]>
26 lines
715 B
TypeScript
26 lines
715 B
TypeScript
import type { NextRequest } from 'next/server'
|
|
|
|
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 })
|
|
}
|