MCPcopy Index your code
hub / github.com/coder/code-server / open

Function open

src/node/util.ts:426–445  ·  view source on GitHub ↗
(address: URL | string)

Source from the content-addressed store, hash-verified

424 * Try opening an address using whatever the system has set for opening URLs.
425 */
426export const open = async (address: URL | string): Promise<void> => {
427 if (typeof address === "string") {
428 throw new Error("Cannot open socket paths")
429 }
430 // Web sockets do not seem to work if browsing with 0.0.0.0.
431 const url = new URL(address)
432 if (url.hostname === "0.0.0.0") {
433 url.hostname = "localhost"
434 }
435 const platform = (await isWsl(process.platform, os.release(), "/proc/version")) ? "wsl" : process.platform
436 const { command, args, urlSearch } = constructOpenOptions(platform, url.search)
437 url.search = urlSearch
438 const proc = cp.spawn(command, [...args, url.toString()], {})
439 await new Promise<void>((resolve, reject) => {
440 proc.on("error", reject)
441 proc.on("close", (code) => {
442 return code !== 0 ? reject(new Error(`Failed to open with code ${code}`)) : resolve()
443 })
444 })
445}
446
447/**
448 * Return a promise that resolves with whether the socket path is active.

Callers 2

runCodeServerFunction · 0.90
openThenWaitCloseMethod · 0.85

Calls 4

isWslFunction · 0.85
constructOpenOptionsFunction · 0.85
resolveFunction · 0.85
spawnMethod · 0.45

Tested by

no test coverage detected