slightly better logging
This commit is contained in:
parent
6361316f14
commit
9c2550150b
|
|
@ -237,9 +237,6 @@ if (process.env.NODE_ENV === "production") {
|
||||||
}
|
}
|
||||||
|
|
||||||
await initNoseDir()
|
await initNoseDir()
|
||||||
initCommands()
|
|
||||||
await initWebapps()
|
|
||||||
initSneakers()
|
|
||||||
|
|
||||||
console.log(color.cyan(NOSE_ICON))
|
console.log(color.cyan(NOSE_ICON))
|
||||||
console.log(color.blue(" BUN_BIN:"), color.yellow(tilde(BUN_BIN)))
|
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_DIR:"), color.yellow(tilde(NOSE_DIR)))
|
||||||
console.log(color.blue("NOSE_ROOT_BIN:"), color.yellow(tilde(NOSE_ROOT_BIN)))
|
console.log(color.blue("NOSE_ROOT_BIN:"), color.yellow(tilde(NOSE_ROOT_BIN)))
|
||||||
|
|
||||||
|
initCommands()
|
||||||
|
await initWebapps()
|
||||||
|
initSneakers()
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
port: process.env.PORT || 3000,
|
port: process.env.PORT || 3000,
|
||||||
hostname: "0.0.0.0",
|
hostname: "0.0.0.0",
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import { sendAll } from "../websocket"
|
||||||
import { expectDir } from "../utils"
|
import { expectDir } from "../utils"
|
||||||
import { NOSE_DIR, BUN_BIN } from "../config"
|
import { NOSE_DIR, BUN_BIN } from "../config"
|
||||||
import { isFile } from "../utils"
|
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<Response>
|
export type Handler = (r: Context) => string | Child | Response | Promise<Response>
|
||||||
export type App = Hono | Handler
|
export type App = Hono | Handler
|
||||||
|
|
@ -80,7 +80,7 @@ function serveStatic(path: string): Response {
|
||||||
|
|
||||||
async function shutdown() {
|
async function shutdown() {
|
||||||
for (const [name, { port, proc }] of processes) {
|
for (const [name, { port, proc }] of processes) {
|
||||||
console.log(`Shutting down ${name}`)
|
webappLog(name, "Shutting down")
|
||||||
try { proc.kill() } catch { }
|
try { proc.kill() } catch { }
|
||||||
}
|
}
|
||||||
process.exit(0)
|
process.exit(0)
|
||||||
|
|
@ -90,7 +90,7 @@ async function restartApp(name: string) {
|
||||||
if (restarting.has(name)) return
|
if (restarting.has(name)) return
|
||||||
restarting.add(name)
|
restarting.add(name)
|
||||||
|
|
||||||
console.log(`[child:${name}]`, "restarting")
|
webappLog(name, "restarting")
|
||||||
const existing = processes.get(name)
|
const existing = processes.get(name)
|
||||||
if (existing) {
|
if (existing) {
|
||||||
try { existing.proc.kill() } catch { }
|
try { existing.proc.kill() } catch { }
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import { join } from "path"
|
import { join } from "path"
|
||||||
import { readdirSync } from "fs"
|
import { readdirSync } from "fs"
|
||||||
|
import color from "kleur"
|
||||||
import type { Child } from "hono/jsx"
|
import type { Child } from "hono/jsx"
|
||||||
import { NOSE_DIR } from "../config"
|
import { NOSE_DIR } from "../config"
|
||||||
import { isFile, isDir } from "../utils"
|
import { isFile, isDir } from "../utils"
|
||||||
|
|
@ -50,4 +51,8 @@ export function isStaticApp(name: string): boolean {
|
||||||
export function appDir(name: string): string | undefined {
|
export function appDir(name: string): string | undefined {
|
||||||
if (isApp(name))
|
if (isApp(name))
|
||||||
return join(NOSE_DIR, name)
|
return join(NOSE_DIR, name)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function webappLog(appName: string, msg: string) {
|
||||||
|
console.log(color.green(`[webapp:${appName}]`), msg)
|
||||||
}
|
}
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
// This is the child process that runs a single webapp.
|
// This is the child process that runs a single webapp.
|
||||||
|
|
||||||
import { Hono } from "hono"
|
import { Hono } from "hono"
|
||||||
import { appPath, toResponse } from "./utils"
|
import { appPath, toResponse, webappLog } from "./utils"
|
||||||
|
|
||||||
const appName = Bun.argv[2]
|
const appName = Bun.argv[2]
|
||||||
if (!appName) {
|
if (!appName) {
|
||||||
|
|
@ -23,4 +23,4 @@ app.all("*", async c => toResponse(await handler(c)))
|
||||||
const port = Number(process.env.PORT || 4000)
|
const port = Number(process.env.PORT || 4000)
|
||||||
Bun.serve({ port, fetch: app.fetch })
|
Bun.serve({ port, fetch: app.fetch })
|
||||||
|
|
||||||
console.log(`[child:${appName}] listening on localhost:${port}`)
|
webappLog(appName, `listening on localhost:${port}`)
|
||||||
Loading…
Reference in New Issue
Block a user