fix(stats): fallback to node server when Bun.serve unavailable

This commit is contained in:
2026-03-29 00:27:53 -07:00
parent 9dae4af773
commit 4ff8529744

View File

@@ -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,19 +1007,23 @@ export function startStatsServer(config: StatsServerConfig): { close: () => void
resolveAnkiNoteId: config.resolveAnkiNoteId,
});
const bunServe = (
globalThis as typeof globalThis & {
Bun: {
serve: (options: {
const bunRuntime = globalThis as typeof globalThis & {
Bun?: {
serve?: (options: {
fetch: (typeof app)['fetch'];
port: number;
hostname: string;
}) => { stop: () => void };
};
}
).Bun.serve;
};
const server = bunServe({
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',
@@ -1026,7 +1031,11 @@ export function startStatsServer(config: StatsServerConfig): { close: () => void
return {
close: () => {
if ('stop' in server) {
server.stop();
} else {
server.close();
}
},
};
}