Add linkup command to improve link functionality
This commit is contained in:
22
src/node/link.ts
Normal file
22
src/node/link.ts
Normal file
@ -0,0 +1,22 @@
|
||||
import { logger } from "@coder/logger"
|
||||
import { spawn } from "child_process"
|
||||
import path from "path"
|
||||
|
||||
export function startLink(port: number): Promise<void> {
|
||||
logger.debug(`running link targetting ${port}`)
|
||||
|
||||
const agent = spawn(path.resolve(__dirname, "../../lib/linkup"), ["--devurl", `code:${port}:code-server`], {
|
||||
shell: false,
|
||||
})
|
||||
return new Promise((res, rej) => {
|
||||
agent.on("error", rej)
|
||||
agent.on("close", (code) => {
|
||||
if (code !== 0) {
|
||||
return rej({
|
||||
message: `Link exited with ${code}`,
|
||||
})
|
||||
}
|
||||
res()
|
||||
})
|
||||
})
|
||||
}
|
@ -8,6 +8,7 @@ import { createApp, ensureAddress } from "./app"
|
||||
import { AuthType, DefaultedArgs, Feature } from "./cli"
|
||||
import { coderCloudBind } from "./coder_cloud"
|
||||
import { commit, version } from "./constants"
|
||||
import { startLink } from "./link"
|
||||
import { register } from "./routes"
|
||||
import { humanPath, isFile, open } from "./util"
|
||||
|
||||
@ -129,6 +130,15 @@ export const runCodeServer = async (args: DefaultedArgs): Promise<http.Server> =
|
||||
logger.info(" - Connected to cloud agent")
|
||||
}
|
||||
|
||||
try {
|
||||
const port = parseInt(serverAddress.split(":").pop() as string, 10)
|
||||
startLink(port).catch((ex) => {
|
||||
logger.debug("Link daemon exited!", field("error", ex))
|
||||
})
|
||||
} catch (ex) {
|
||||
logger.debug("Failed to start link daemon!", ex)
|
||||
}
|
||||
|
||||
if (args.enable && args.enable.length > 0) {
|
||||
logger.info("Enabling the following experimental features:")
|
||||
args.enable.forEach((feature) => {
|
||||
|
Reference in New Issue
Block a user