mirror of
https://github.com/coder/code-server.git
synced 2025-07-31 05:54:15 +08:00
coder-cloud: Use consolidated bind command
This commit is contained in:
@ -5,8 +5,8 @@ import split2 from "split2"
|
||||
|
||||
const coderCloudAgent = path.resolve(__dirname, "../../lib/coder-cloud-agent")
|
||||
|
||||
export async function coderCloudBind(serverName: string): Promise<void> {
|
||||
const agent = spawn(coderCloudAgent, ["link", serverName], {
|
||||
function runAgent(...args: string[]): Promise<void> {
|
||||
const agent = spawn(coderCloudAgent, args, {
|
||||
stdio: ["inherit", "inherit", "pipe"],
|
||||
})
|
||||
|
||||
@ -30,43 +30,9 @@ export async function coderCloudBind(serverName: string): Promise<void> {
|
||||
})
|
||||
}
|
||||
|
||||
export function coderCloudProxy(addr: string) {
|
||||
export function coderCloudBind(csAddr: string, serverName = ""): Promise<void> {
|
||||
// addr needs to be in host:port format.
|
||||
// So we trim the protocol.
|
||||
addr = addr.replace(/^https?:\/\//, "")
|
||||
|
||||
const _proxy = async () => {
|
||||
const agent = spawn(coderCloudAgent, ["proxy", "--code-server-addr", addr], {
|
||||
stdio: ["inherit", "inherit", "pipe"],
|
||||
})
|
||||
|
||||
agent.stderr.pipe(split2()).on("data", (line) => {
|
||||
line = line.replace(/^[0-9-]+ [0-9:]+ [^ ]+\t/, "")
|
||||
logger.info(line)
|
||||
})
|
||||
|
||||
return new Promise((res, rej) => {
|
||||
agent.on("error", rej)
|
||||
|
||||
agent.on("close", (code) => {
|
||||
if (code !== 0) {
|
||||
rej({
|
||||
message: `coder cloud agent exited with ${code}`,
|
||||
})
|
||||
return
|
||||
}
|
||||
res()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
const proxy = async () => {
|
||||
try {
|
||||
await _proxy()
|
||||
} catch (err) {
|
||||
logger.error(err.message)
|
||||
}
|
||||
setTimeout(proxy, 3000)
|
||||
}
|
||||
proxy()
|
||||
csAddr = csAddr.replace(/^https?:\/\//, "")
|
||||
return runAgent("bind", `--code-server-addr=${csAddr}`, serverName)
|
||||
}
|
||||
|
Reference in New Issue
Block a user