| 1 | export const dynamic = "force-dynamic"; |
| 2 | |
| 3 | export function GET() { |
| 4 | const encoder = new TextEncoder(); |
| 5 | let timer: ReturnType<typeof setTimeout>; |
| 6 | const body = new ReadableStream<Uint8Array>({ |
| 7 | start(controller) { |
| 8 | controller.enqueue(encoder.encode("data: first\n\n")); |
| 9 | timer = setTimeout(() => { |
| 10 | controller.enqueue(encoder.encode("data: second\n\n")); |
| 11 | controller.close(); |
| 12 | }, 50); |
| 13 | }, |
| 14 | cancel() { |
| 15 | clearTimeout(timer); |
| 16 | }, |
| 17 | }); |
| 18 | return new Response(body, { |
| 19 | headers: { |
| 20 | "content-type": "text/event-stream", |
| 21 | "cache-control": "no-store", |
| 22 | }, |
| 23 | }); |
| 24 | } |