Skip to content

Commit c3c24fe

Browse files
committed
Fixes for @ammarb
1 parent 6e8248c commit c3c24fe

File tree

3 files changed

+14
-18
lines changed

3 files changed

+14
-18
lines changed

src/node/cli.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export interface Args extends VsArgs {
4848
readonly "reuse-window"?: boolean
4949
readonly "new-window"?: boolean
5050

51-
readonly "coder-link"?: OptionalString
51+
readonly "coder-bind"?: string
5252
}
5353

5454
interface Option<T> {
@@ -159,10 +159,10 @@ const options: Options<Required<Args>> = {
159159
log: { type: LogLevel },
160160
verbose: { type: "boolean", short: "vvv", description: "Enable verbose logging." },
161161

162-
"coder-link": {
163-
type: OptionalString,
162+
"coder-bind": {
163+
type: "string",
164164
description: `
165-
Securely link code-server via Coder Cloud with the passed name. You'll get a URL like
165+
Securely bind code-server via Coder Cloud with the passed name. You'll get a URL like
166166
https://myname.coder-cloud.com at which you can easily access your code-server instance.
167167
Authorization is done via GitHub. Only the first code-server spawned with the current
168168
configuration will be accessible.`,

src/node/coder-cloud.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import xdgBasedir from "xdg-basedir"
99

1010
const coderCloudAgent = path.resolve(__dirname, "../../lib/coder-cloud-agent")
1111

12-
export async function coderCloudLink(serverName: string): Promise<void> {
12+
export async function coderCloudBind(serverName: string): Promise<void> {
1313
const agent = spawn(coderCloudAgent, ["link", serverName], {
1414
stdio: ["inherit", "inherit", "pipe"],
1515
})

src/node/entry.ts

+9-13
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { StaticHttpProvider } from "./app/static"
1212
import { UpdateHttpProvider } from "./app/update"
1313
import { VscodeHttpProvider } from "./app/vscode"
1414
import { Args, bindAddrFromAllSources, optionDescriptions, parse, readConfigFile, setDefaults } from "./cli"
15-
import { coderCloudLink, coderCloudProxy } from "./coder-cloud"
15+
import { coderCloudBind, coderCloudProxy } from "./coder-cloud"
1616
import { AuthType, HttpServer, HttpServerOptions } from "./http"
1717
import { loadPlugins } from "./plugin"
1818
import { generateCertificate, hash, humanPath, open } from "./util"
@@ -36,13 +36,15 @@ const version = pkg.version || "development"
3636
const commit = pkg.commit || "development"
3737

3838
const main = async (args: Args, cliArgs: Args, configArgs: Args): Promise<void> => {
39-
if (args["coder-link"]) {
40-
// If we're being exposed to the cloud, we listen on a random address.
39+
if (args["coder-bind"]) {
40+
// If we're being exposed to the cloud, we listen on a random address and disable auth.
4141
args = {
4242
...args,
4343
host: "localhost",
4444
port: 0,
45+
auth: AuthType.None,
4546
}
47+
logger.info("coder-bind: disabling auth and listening on random localhost port")
4648
}
4749

4850
if (!args.auth) {
@@ -132,25 +134,19 @@ const main = async (args: Args, cliArgs: Args, configArgs: Args): Promise<void>
132134
httpServer.proxyDomains.forEach((domain) => logger.info(` - *.${domain}`))
133135
}
134136

135-
coderCloudProxy(serverAddress!)
136-
137137
if (serverAddress && !options.socket && args.open) {
138138
// The web socket doesn't seem to work if browsing with 0.0.0.0.
139139
const openAddress = serverAddress.replace(/:\/\/0.0.0.0/, "://localhost")
140140
await open(openAddress).catch(console.error)
141141
logger.info(`Opened ${openAddress}`)
142142
}
143143

144-
if (args["coder-link"]) {
145-
if (!args["coder-link"].value) {
146-
logger.error("You must pass a name to link with coder cloud. See --help")
147-
process.exit(1)
148-
}
149-
150-
logger.info(`linking code-server to the cloud with name ${args["coder-link"].value}`)
144+
if (args["coder-bind"]) {
145+
logger.info(`linking code-server to the cloud with name ${args["coder-bind"]}`)
151146

152147
try {
153-
await coderCloudLink(args["coder-link"].value)
148+
await coderCloudBind(args["coder-bind"])
149+
coderCloudProxy(serverAddress!)
154150
} catch (err) {
155151
logger.error(err.message)
156152
process.exit(1)

0 commit comments

Comments
 (0)