From 4ff85297440fa86e80c8c325b91822beb1160c3a Mon Sep 17 00:00:00 2001 From: sudacode Date: Sun, 29 Mar 2026 00:27:53 -0700 Subject: [PATCH] fix(stats): fallback to node server when Bun.serve unavailable --- src/core/services/stats-server.ts | 43 +++++++++++++++++++------------ 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/src/core/services/stats-server.ts b/src/core/services/stats-server.ts index 328d6d3..591657b 100644 --- a/src/core/services/stats-server.ts +++ b/src/core/services/stats-server.ts @@ -1,4 +1,5 @@ import { Hono } from 'hono'; +import { serve } from '@hono/node-server'; import type { ImmersionTrackerService } from './immersion-tracker-service.js'; import { basename, extname, resolve, sep } from 'node:path'; import { readFileSync, existsSync, statSync } from 'node:fs'; @@ -1006,27 +1007,35 @@ export function startStatsServer(config: StatsServerConfig): { close: () => void resolveAnkiNoteId: config.resolveAnkiNoteId, }); - const bunServe = ( - globalThis as typeof globalThis & { - Bun: { - serve: (options: { - fetch: (typeof app)['fetch']; - port: number; - hostname: string; - }) => { stop: () => void }; - }; - } - ).Bun.serve; + const bunRuntime = globalThis as typeof globalThis & { + Bun?: { + serve?: (options: { + fetch: (typeof app)['fetch']; + port: number; + hostname: string; + }) => { stop: () => void }; + }; + }; - const server = bunServe({ - fetch: app.fetch, - port: config.port, - hostname: '127.0.0.1', - }); + const server = bunRuntime.Bun?.serve + ? bunRuntime.Bun.serve({ + fetch: app.fetch, + port: config.port, + hostname: '127.0.0.1', + }) + : serve({ + fetch: app.fetch, + port: config.port, + hostname: '127.0.0.1', + }); return { close: () => { - server.stop(); + if ('stop' in server) { + server.stop(); + } else { + server.close(); + } }, }; }