| 1 | import { Hono } from "hono"; |
| 2 | import type { Bindings } from "../types"; |
| 3 | |
| 4 | const jetstream = new Hono<{ Bindings: Bindings }>(); |
| 5 | |
| 6 | function getStub(env: Bindings) { |
| 7 | const id = env.JETSTREAM_CONSUMER.idFromName("singleton"); |
| 8 | return env.JETSTREAM_CONSUMER.get(id); |
| 9 | } |
| 10 | |
| 11 | jetstream.get("/start", async (c) => { |
| 12 | const stub = getStub(c.env); |
| 13 | const resp = await stub.fetch(new Request("http://do/start")); |
| 14 | return c.json(await resp.json()); |
| 15 | }); |
| 16 | |
| 17 | jetstream.get("/status", async (c) => { |
| 18 | const stub = getStub(c.env); |
| 19 | const resp = await stub.fetch(new Request("http://do/status")); |
| 20 | return c.json(await resp.json()); |
| 21 | }); |
| 22 | |
| 23 | jetstream.get("/stop", async (c) => { |
| 24 | const stub = getStub(c.env); |
| 25 | const resp = await stub.fetch(new Request("http://do/stop")); |
| 26 | return c.json(await resp.json()); |
| 27 | }); |
| 28 | |
| 29 | export default jetstream; |