From 9c2550150bb70e454aa9d4674ca5068249765340 Mon Sep 17 00:00:00 2001 From: Chris Wanstrath Date: Fri, 10 Oct 2025 16:00:38 -0700 Subject: [PATCH] slightly better logging --- src/server.tsx | 7 ++++--- src/webapp/server.ts | 6 +++--- src/webapp/utils.ts | 5 +++++ src/webapp/worker.ts | 4 ++-- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/server.tsx b/src/server.tsx index c0c1659..5059004 100644 --- a/src/server.tsx +++ b/src/server.tsx @@ -237,9 +237,6 @@ if (process.env.NODE_ENV === "production") { } await initNoseDir() -initCommands() -await initWebapps() -initSneakers() console.log(color.cyan(NOSE_ICON)) console.log(color.blue(" BUN_BIN:"), color.yellow(tilde(BUN_BIN))) @@ -248,6 +245,10 @@ console.log(color.blue(" NOSE_DATA:"), color.yellow(tilde(NOSE_DATA))) console.log(color.blue(" NOSE_DIR:"), color.yellow(tilde(NOSE_DIR))) console.log(color.blue("NOSE_ROOT_BIN:"), color.yellow(tilde(NOSE_ROOT_BIN))) +initCommands() +await initWebapps() +initSneakers() + export default { port: process.env.PORT || 3000, hostname: "0.0.0.0", diff --git a/src/webapp/server.ts b/src/webapp/server.ts index 2c8a39d..471107b 100644 --- a/src/webapp/server.ts +++ b/src/webapp/server.ts @@ -9,7 +9,7 @@ import { sendAll } from "../websocket" import { expectDir } from "../utils" import { NOSE_DIR, BUN_BIN } from "../config" import { isFile } from "../utils" -import { apps, isApp, appDir, isStaticApp } from "./utils" +import { apps, isApp, appDir, isStaticApp, webappLog } from "./utils" export type Handler = (r: Context) => string | Child | Response | Promise export type App = Hono | Handler @@ -80,7 +80,7 @@ function serveStatic(path: string): Response { async function shutdown() { for (const [name, { port, proc }] of processes) { - console.log(`Shutting down ${name}`) + webappLog(name, "Shutting down") try { proc.kill() } catch { } } process.exit(0) @@ -90,7 +90,7 @@ async function restartApp(name: string) { if (restarting.has(name)) return restarting.add(name) - console.log(`[child:${name}]`, "restarting") + webappLog(name, "restarting") const existing = processes.get(name) if (existing) { try { existing.proc.kill() } catch { } diff --git a/src/webapp/utils.ts b/src/webapp/utils.ts index 4bc70e0..228ccd9 100644 --- a/src/webapp/utils.ts +++ b/src/webapp/utils.ts @@ -1,5 +1,6 @@ import { join } from "path" import { readdirSync } from "fs" +import color from "kleur" import type { Child } from "hono/jsx" import { NOSE_DIR } from "../config" import { isFile, isDir } from "../utils" @@ -50,4 +51,8 @@ export function isStaticApp(name: string): boolean { export function appDir(name: string): string | undefined { if (isApp(name)) return join(NOSE_DIR, name) +} + +export function webappLog(appName: string, msg: string) { + console.log(color.green(`[webapp:${appName}]`), msg) } \ No newline at end of file diff --git a/src/webapp/worker.ts b/src/webapp/worker.ts index 178da56..750a800 100644 --- a/src/webapp/worker.ts +++ b/src/webapp/worker.ts @@ -2,7 +2,7 @@ // This is the child process that runs a single webapp. import { Hono } from "hono" -import { appPath, toResponse } from "./utils" +import { appPath, toResponse, webappLog } from "./utils" const appName = Bun.argv[2] if (!appName) { @@ -23,4 +23,4 @@ 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}`) \ No newline at end of file +webappLog(appName, `listening on localhost:${port}`) \ No newline at end of file