| 103 | } |
| 104 | |
| 105 | function startBunStudioServer({ handler, onListen, port }: StartStudioServerOptions): StudioServer { |
| 106 | const bun = ( |
| 107 | globalThis as typeof globalThis & { |
| 108 | Bun?: { |
| 109 | serve(options: { fetch: StudioRequestHandler; port: number }): { stop(closeActiveConnections?: boolean): void } |
| 110 | } |
| 111 | } |
| 112 | ).Bun |
| 113 | |
| 114 | if (!bun) { |
| 115 | throw new Error('Bun runtime is not available.') |
| 116 | } |
| 117 | |
| 118 | const server = bun.serve({ |
| 119 | fetch: handler, |
| 120 | port, |
| 121 | }) |
| 122 | |
| 123 | onListen() |
| 124 | |
| 125 | return { |
| 126 | close() { |
| 127 | server.stop(true) |
| 128 | }, |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | function startDenoStudioServer({ handler, onListen, port }: StartStudioServerOptions): StudioServer { |
| 133 | const abortController = new AbortController() |