Skip to content

Commit af28885

Browse files
committed
Deprecate --host and --port in favour of --bind-addr
1 parent f21ba53 commit af28885

File tree

5 files changed

+23
-6
lines changed

5 files changed

+23
-6
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
build
44
dist*
55
out*
6-
release*
6+
release/
77
node_modules
88
binaries

ci/release-image/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ RUN cd /tmp && tar -xzf code-server*.tar.gz && rm code-server*.tar.gz && \
4040
EXPOSE 8080
4141
USER coder
4242
WORKDIR /home/coder
43-
ENTRYPOINT ["dumb-init", "fixuid", "-q", "/usr/local/bin/code-server", "--host", "0.0.0.0", "."]
43+
ENTRYPOINT ["dumb-init", "fixuid", "-q", "/usr/local/bin/code-server", "--bind-addr", "0.0.0.0:8080", "."]

src/node/cli.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export interface Args extends VsArgs {
3030
log?: LogLevel
3131
readonly open?: boolean
3232
readonly port?: number
33+
readonly "bind-addr"?: string
3334
readonly socket?: string
3435
readonly version?: boolean
3536
readonly force?: boolean
@@ -88,11 +89,16 @@ const options: Options<Required<Args>> = {
8889
"cert-key": { type: "string", path: true, description: "Path to certificate key when using non-generated cert." },
8990
"disable-updates": { type: "boolean", description: "Disable automatic updates." },
9091
"disable-telemetry": { type: "boolean", description: "Disable telemetry." },
91-
host: { type: "string", description: "Host for the HTTP server." },
9292
help: { type: "boolean", short: "h", description: "Show this output." },
9393
json: { type: "boolean" },
9494
open: { type: "boolean", description: "Open in browser on startup. Does not work remotely." },
95-
port: { type: "number", description: "Port for the HTTP server." },
95+
96+
"bind-addr": { type: "string", description: "Address to bind to in host:port." },
97+
98+
// These two have been deprecated by bindAddr.
99+
host: { type: "string", description: "" },
100+
port: { type: "number", description: "" },
101+
96102
socket: { type: "string", path: true, description: "Path to a socket (host and port will be ignored)." },
97103
version: { type: "boolean", short: "v", description: "Display version information." },
98104
_: { type: "string[]" },

src/node/entry.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,21 @@ const main = async (args: Args): Promise<void> => {
3535
const auth = args.auth || AuthType.Password
3636
const originalPassword = auth === AuthType.Password && (process.env.PASSWORD || (await generatePassword()))
3737

38+
let host = args.host
39+
let port = args.port
40+
if (args["bind-addr"] !== undefined) {
41+
const u = new URL(`http://${args["bind-addr"]}`)
42+
host = u.hostname
43+
port = parseInt(u.port, 10)
44+
}
45+
3846
// Spawn the main HTTP server.
3947
const options: HttpServerOptions = {
4048
auth,
4149
commit,
42-
host: args.host || (args.auth === AuthType.Password && typeof args.cert !== "undefined" ? "0.0.0.0" : "localhost"),
50+
host: host || (args.auth === AuthType.Password && args.cert !== undefined ? "0.0.0.0" : "localhost"),
4351
password: originalPassword ? hash(originalPassword) : undefined,
44-
port: typeof args.port !== "undefined" ? args.port : process.env.PORT ? parseInt(process.env.PORT, 10) : 8080,
52+
port: port !== undefined ? port : process.env.PORT ? parseInt(process.env.PORT, 10) : 8080,
4553
proxyDomains: args["proxy-domain"],
4654
socket: args.socket,
4755
...(args.cert && !args.cert.value

test/cli.test.ts

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ describe("cli", () => {
1919
it("should parse all available options", () => {
2020
assert.deepEqual(
2121
parse([
22+
"--bind-addr=192.169.0.1:8080",
2223
"--auth",
2324
"none",
2425
"--extensions-dir",
@@ -74,6 +75,7 @@ describe("cli", () => {
7475
"user-data-dir": path.resolve("bar"),
7576
verbose: true,
7677
version: true,
78+
"bind-addr": "192.169.0.1:8080",
7779
},
7880
)
7981
})
@@ -117,6 +119,7 @@ describe("cli", () => {
117119
assert.throws(() => parse(["--auth=", "--log=debug"]), /--auth requires a value/)
118120
assert.throws(() => parse(["--auth", "--log"]), /--auth requires a value/)
119121
assert.throws(() => parse(["--auth", "--invalid"]), /--auth requires a value/)
122+
assert.throws(() => parse(["--bind-addr"]), /--bind-addr requires a value/)
120123
})
121124

122125
it("should error if value is invalid", () => {

0 commit comments

Comments
 (0)