feat(server): add --mdns-domain flag to customize mDNS hostname (#11796)

This commit is contained in:
Luiz Guilherme D'Abruzzo Pereira
2026-02-02 17:52:32 -03:00
committed by GitHub
parent 824165eb79
commit a9fca05d8b
5 changed files with 21 additions and 6 deletions

View File

@@ -7,17 +7,18 @@ export namespace MDNS {
let bonjour: Bonjour | undefined
let currentPort: number | undefined
export function publish(port: number) {
export function publish(port: number, domain?: string) {
if (currentPort === port) return
if (bonjour) unpublish()
try {
const host = domain ?? "opencode.local"
const name = `opencode-${port}`
bonjour = new Bonjour()
const service = bonjour.publish({
name,
type: "http",
host: "opencode.local",
host,
port,
txt: { path: "/" },
})

View File

@@ -563,7 +563,13 @@ export namespace Server {
return result
}
export function listen(opts: { port: number; hostname: string; mdns?: boolean; cors?: string[] }) {
export function listen(opts: {
port: number
hostname: string
mdns?: boolean
mdnsDomain?: string
cors?: string[]
}) {
_corsWhitelist = opts.cors ?? []
const args = {
@@ -591,7 +597,7 @@ export namespace Server {
opts.hostname !== "localhost" &&
opts.hostname !== "::1"
if (shouldPublishMDNS) {
MDNS.publish(server.port!)
MDNS.publish(server.port!, opts.mdnsDomain)
} else if (opts.mdns) {
log.warn("mDNS enabled but hostname is loopback; skipping mDNS publish")
}