add new subdomains
This commit is contained in:
parent
74a101db93
commit
38c4900dbb
|
|
@ -1,8 +1,8 @@
|
|||
import { type Context, Hono } from "hono"
|
||||
import type { Child } from "hono/jsx"
|
||||
import { renderToString } from "hono/jsx/dom/server"
|
||||
import { join } from "node:path"
|
||||
import { readdirSync } from "node:fs"
|
||||
import { join } from "path"
|
||||
import { readdirSync, watch } from "fs"
|
||||
import { NOSE_WWW } from "./config"
|
||||
import { isFile } from "./utils"
|
||||
|
||||
|
|
@ -70,22 +70,39 @@ export function toResponse(source: string | Child | Response): Response {
|
|||
})
|
||||
}
|
||||
|
||||
//
|
||||
// dns nonsense
|
||||
//
|
||||
|
||||
const dnsEntries: Record<string, any> = {}
|
||||
|
||||
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()
|
||||
|
||||
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])
|
||||
)
|
||||
apps().forEach(publishAppDNS)
|
||||
|
||||
const signals = ["SIGINT", "SIGTERM"]
|
||||
signals.forEach(sig =>
|
||||
process.on(sig, () => {
|
||||
procs.forEach(p => p.kill("SIGTERM"))
|
||||
process.exit(0)
|
||||
for (const name in dnsEntries)
|
||||
dnsEntries[name].kill("SIGTERM")
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
function publishAppDNS(app: string) {
|
||||
if (process.env.BUN_HOT) return
|
||||
|
||||
if (!dnsEntries[app])
|
||||
dnsEntries[app] = Bun.spawn(["avahi-publish", "-a", `${app}.${host}.local`, "-R", ip])
|
||||
|
||||
return dnsEntries[app]
|
||||
}
|
||||
|
||||
const appWatcher = watch(NOSE_WWW, (event, filename) => {
|
||||
apps().forEach(publishAppDNS)
|
||||
})
|
||||
Loading…
Reference in New Issue
Block a user