nose-pluto/src/webapp/worker.ts
2025-10-10 15:40:40 -07:00

26 lines
717 B
TypeScript

////
// This is the child process that runs a single webapp.
import { Hono } from "hono"
import { appPath, toResponse } from "./utils"
const appName = Bun.argv[2]
if (!appName) {
console.log("usage: bun run ./src/webapp/worker.ts <app-name>")
process.exit(1)
}
const path = await appPath(appName)
if (!path) throw `Can't find app: ${appName}`
const mod = await import(path)
const handler = mod.default
if (typeof handler !== "function") throw `no default export in ${appName}`
const app = new Hono()
app.all("*", async c => toResponse(await handler(c)))
const port = Number(process.env.PORT || 4000)
Bun.serve({ port, fetch: app.fetch })
console.log(`[child:${appName}] listening on localhost:${port}`)