aboutsummaryrefslogtreecommitdiff
path: root/test/js/bun/http/sse-demo.ts
blob: adec1420b2e4304e92e32c2c1a3841e7a715627c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { EventStream, serve } from "bun";

serve({
  port: 3000,
  fetch(req) {
    return new Response(
      new EventStream({
        start(controller) {
          setTimeout(() => {
            controller.send("hi");
            // controller.close();
          }, 1000);
        },
        cancel() {
          console.log("CANCEL");
        },
      }),
      {
        headers: {
          "Content-Bruh": "text/bruh",
          "Content-Length": "452",
        },
      },
    );
  },
});

// // serve({
// //   port: 3000,
// //   fetch(req) {
// //     return new Response(new Blob(["hello world"], { type: "custom/type" }));
// //   },
// // });