add new subdomains
This commit is contained in:
parent
74a101db93
commit
38c4900dbb
|
|
@ -1,8 +1,8 @@
|
||||||
import { type Context, Hono } from "hono"
|
import { type Context, Hono } from "hono"
|
||||||
import type { Child } from "hono/jsx"
|
import type { Child } from "hono/jsx"
|
||||||
import { renderToString } from "hono/jsx/dom/server"
|
import { renderToString } from "hono/jsx/dom/server"
|
||||||
import { join } from "node:path"
|
import { join } from "path"
|
||||||
import { readdirSync } from "node:fs"
|
import { readdirSync, watch } from "fs"
|
||||||
import { NOSE_WWW } from "./config"
|
import { NOSE_WWW } from "./config"
|
||||||
import { isFile } from "./utils"
|
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() {
|
export async function publishDNS() {
|
||||||
const { stdout: ipRaw } = await Bun.$`hostname -I | awk '{print $1}'`.quiet()
|
apps().forEach(publishAppDNS)
|
||||||
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"]
|
const signals = ["SIGINT", "SIGTERM"]
|
||||||
signals.forEach(sig =>
|
signals.forEach(sig =>
|
||||||
process.on(sig, () => {
|
process.on(sig, () => {
|
||||||
procs.forEach(p => p.kill("SIGTERM"))
|
for (const name in dnsEntries)
|
||||||
process.exit(0)
|
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