diff --git a/apps/vps/src/app.ts b/apps/vps/src/app.ts index b6d6dfc9..f3ebe56c 100644 --- a/apps/vps/src/app.ts +++ b/apps/vps/src/app.ts @@ -135,11 +135,21 @@ const sitemapRegenerationEffect = regenerateSitemap.pipe( const mainEffect = setupRoutesEffect +// Registered by the entry point (src/index.ts) to dispose the Effect +// HttpRouter handler before the runtime shuts down. No-op until Step 2b wires +// the entry point to serve through it (docs/migration-effect-http-api.md). +let disposeWebHandler: (() => Promise) | undefined + +export const onShutdown = (dispose: () => Promise) => { + disposeWebHandler = dispose +} + const setupGracefulShutdown = () => { const shutdown = async (signal: string) => { console.log(`Graceful shutdown initiated via ${signal}`) try { + await disposeWebHandler?.() const { disposeRuntime } = await import('./runtime') await disposeRuntime() console.log('Runtime disposed successfully') diff --git a/apps/vps/src/index.ts b/apps/vps/src/index.ts index 9755dad9..32b681d8 100644 --- a/apps/vps/src/index.ts +++ b/apps/vps/src/index.ts @@ -1,14 +1,18 @@ export const localVPSPort = 3003 -const { default: app } = await import('./app') +const { default: app, onShutdown } = await import('./app') -// Step 2a (docs/migration-effect-http-api.md): proves the toWebHandler + fallback -// layer builds and serves identically to the Hono app. Not wired to Bun.serve yet. +// Step 2 (docs/migration-effect-http-api.md): the process now serves through +// this handler. It wildcards every request to the same Hono app unchanged -- +// app.ts still owns route setup, background forks, and its SIGTERM/SIGINT +// wiring. This is where the serving topology changes. const { createWebHandler } = await import('./http/routes') export const effectWebHandler = createWebHandler(app) +onShutdown(effectWebHandler.dispose) + export default { port: localVPSPort, - fetch: app.fetch, + fetch: effectWebHandler.handler, maxRequestBodySize: 1024 * 1024 * 1000 // 1GB }