fix: mdns discover hostname (#9039)
This commit is contained in:
@@ -60,7 +60,7 @@ export const WebCommand = cmd({
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (opts.mdns) {
|
if (opts.mdns) {
|
||||||
UI.println(UI.Style.TEXT_INFO_BOLD + " mDNS: ", UI.Style.TEXT_NORMAL, "opencode.local")
|
UI.println(UI.Style.TEXT_INFO_BOLD + " mDNS: ", UI.Style.TEXT_NORMAL, `opencode.local:${server.port}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open localhost in browser
|
// Open localhost in browser
|
||||||
|
|||||||
@@ -7,15 +7,17 @@ export namespace MDNS {
|
|||||||
let bonjour: Bonjour | undefined
|
let bonjour: Bonjour | undefined
|
||||||
let currentPort: number | undefined
|
let currentPort: number | undefined
|
||||||
|
|
||||||
export function publish(port: number, name = "opencode") {
|
export function publish(port: number) {
|
||||||
if (currentPort === port) return
|
if (currentPort === port) return
|
||||||
if (bonjour) unpublish()
|
if (bonjour) unpublish()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const name = `opencode-${port}`
|
||||||
bonjour = new Bonjour()
|
bonjour = new Bonjour()
|
||||||
const service = bonjour.publish({
|
const service = bonjour.publish({
|
||||||
name,
|
name,
|
||||||
type: "http",
|
type: "http",
|
||||||
|
host: "opencode.local",
|
||||||
port,
|
port,
|
||||||
txt: { path: "/" },
|
txt: { path: "/" },
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -562,7 +562,7 @@ export namespace Server {
|
|||||||
opts.hostname !== "localhost" &&
|
opts.hostname !== "localhost" &&
|
||||||
opts.hostname !== "::1"
|
opts.hostname !== "::1"
|
||||||
if (shouldPublishMDNS) {
|
if (shouldPublishMDNS) {
|
||||||
MDNS.publish(server.port!, `opencode-${server.port!}`)
|
MDNS.publish(server.port!)
|
||||||
} else if (opts.mdns) {
|
} else if (opts.mdns) {
|
||||||
log.warn("mDNS enabled but hostname is loopback; skipping mDNS publish")
|
log.warn("mDNS enabled but hostname is loopback; skipping mDNS publish")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user