This commit is contained in:
Chris Wanstrath 2025-09-16 21:56:30 -07:00
parent ba344610ab
commit 74a101db93
4 changed files with 24 additions and 25 deletions

View File

@ -11,8 +11,7 @@
"remote:install": "./scripts/remote-install.sh", "remote:install": "./scripts/remote-install.sh",
"remote:start": "./scripts/remote-start.sh", "remote:start": "./scripts/remote-start.sh",
"remote:stop": "./scripts/remote-stop.sh", "remote:stop": "./scripts/remote-stop.sh",
"remote:restart": "./scripts/remote-restart.sh", "remote:restart": "./scripts/remote-restart.sh"
"generate-hosts": "./scripts/generate-hosts.sh"
}, },
"alias": { "alias": {
"@utils": "./src/utils.tsx", "@utils": "./src/utils.tsx",

View File

@ -1,22 +0,0 @@
import { $ } from "bun"
import { apps } from "../src/webapp"
const { stdout: ipRaw } = await $`hostname -I | awk '{print $1}'`.quiet()
const { stdout: hostRaw } = await $`hostname`.quiet()
const ip = ipRaw.toString().trim()
const host = hostRaw.toString().trim()
console.log(apps().map(app => `avahi-publish -a ${app}.${host}.local -R ${ip}`).join("\n"))
const procs = apps().map(app =>
Bun.spawn(["avahi-publish", "-a", `${app}.${host}.local`, "-R", ip])
)
for (const p of procs)
p.exited.then(code =>
console.log(`avahi-publish (${p.pid}) exited with code ${code}`)
)
await new Promise(() => { })

View File

@ -5,7 +5,7 @@ import color from "kleur"
import { NOSE_ICON, NOSE_DIR, NOSE_BIN, NOSE_WWW } from "./config" import { NOSE_ICON, NOSE_DIR, NOSE_BIN, NOSE_WWW } from "./config"
import { transpile, isFile, tilde } from "./utils" import { transpile, isFile, tilde } from "./utils"
import { apps, serveApp } from "./webapp" import { apps, serveApp, publishDNS } from "./webapp"
import { Layout } from "./components/layout" import { Layout } from "./components/layout"
import { Terminal } from "./components/terminal" import { Terminal } from "./components/terminal"
@ -97,6 +97,8 @@ if (process.env.BUN_HOT) {
process.exit() process.exit()
}) })
} }
} else {
publishDNS()
} }

View File

@ -69,3 +69,23 @@ export function toResponse(source: string | Child | Response): Response {
} }
}) })
} }
export async function publishDNS() {
const { stdout: ipRaw } = await Bun.$`hostname -I | awk '{print $1}'`.quiet()
const { stdout: hostRaw } = await Bun.$`hostname`.quiet()
const ip = ipRaw.toString().trim()
const host = hostRaw.toString().trim()
const procs = apps().map(app =>
Bun.spawn(["avahi-publish", "-a", `${app}.${host}.local`, "-R", ip])
)
const signals = ["SIGINT", "SIGTERM"]
signals.forEach(sig =>
process.on(sig, () => {
procs.forEach(p => p.kill("SIGTERM"))
process.exit(0)
})
)
}