Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions apps/vps/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>) | undefined

export const onShutdown = (dispose: () => Promise<void>) => {
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')
Expand Down
12 changes: 8 additions & 4 deletions apps/vps/src/index.ts
Original file line number Diff line number Diff line change
@@ -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
}