From 926134f35e54572948773fbb3c5c305180397ee2 Mon Sep 17 00:00:00 2001 From: Neko Ayaka Date: Fri, 28 Nov 2025 14:27:18 +0800 Subject: [PATCH] fix(stage-tamagotchi): omit server startup error --- .../services/airi/channel-server/index.ts | 47 ++++++++++--------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/apps/stage-tamagotchi/src/main/services/airi/channel-server/index.ts b/apps/stage-tamagotchi/src/main/services/airi/channel-server/index.ts index 16e6dbb21..80af346b6 100644 --- a/apps/stage-tamagotchi/src/main/services/airi/channel-server/index.ts +++ b/apps/stage-tamagotchi/src/main/services/airi/channel-server/index.ts @@ -14,32 +14,37 @@ export async function setupChannelServer() { const { serve } = await import('h3') const { plugin: ws } = await import('crossws/server') - const serverInstance = serve(serverRuntime.app, { + try { + const serverInstance = serve(serverRuntime.app, { // TODO: fix types // @ts-expect-error - the .crossws property wasn't extended in types - plugins: [ws({ resolve: async req => (await serverRuntime.app.fetch(req)).crossws })], - port: env.PORT ? Number(env.PORT) : 6121, - hostname: env.SERVER_RUNTIME_HOSTNAME || 'localhost', - reusePort: true, - gracefulShutdown: { - forceTimeout: 500, - gracefulTimeout: 500, - }, - }) + plugins: [ws({ resolve: async req => (await serverRuntime.app.fetch(req)).crossws })], + port: env.PORT ? Number(env.PORT) : 6121, + hostname: env.SERVER_RUNTIME_HOSTNAME || 'localhost', + reusePort: true, + gracefulShutdown: { + forceTimeout: 500, + gracefulTimeout: 500, + }, + }) - log.log('@proj-airi/server-runtime started on ws://localhost:6121') + log.log('@proj-airi/server-runtime started on ws://localhost:6121') - onAppBeforeQuit(async () => { - if (serverInstance && typeof serverInstance.close === 'function') { - try { - await serverInstance.close() - log.log('WebSocket server closed') + onAppBeforeQuit(async () => { + if (serverInstance && typeof serverInstance.close === 'function') { + try { + await serverInstance.close() + log.log('WebSocket server closed') + } + catch (error) { + log.withError(error).error('Error closing WebSocket server') + } } - catch (error) { - log.withError(error).error('Error closing WebSocket server') - } - } - }) + }) + } + catch (error) { + log.withError(error).error('failed to start WebSocket server') + } } catch (error) { log.withError(error).error('failed to start WebSocket server')