Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/node/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,9 @@ export function bindAddrFromArgs(addr: Addr, args: UserProvidedArgs): Addr {
if (args["bind-addr"]) {
addr = parseBindAddr(args["bind-addr"])
}
if (process.env.HOST) {
addr.host = process.env.HOST
}
if (args.host) {
addr.host = args.host
}
Expand Down
44 changes: 44 additions & 0 deletions test/unit/node/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,50 @@ describe("bindAddrFromArgs", () => {
expect(actual).toStrictEqual(expected)
})

it("should use process.env.HOST if set", () => {
const [setValue, resetValue] = useEnv("HOST")
setValue("coder")

const args: UserProvidedArgs = {}

const addr = {
host: "localhost",
port: 8080,
}

const actual = bindAddrFromArgs(addr, args)
const expected = {
host: "coder",
port: 8080,
}

expect(actual).toStrictEqual(expected)
resetValue()
})

it("should use the args.host over process.env.HOST if both set", () => {
const [setValue, resetValue] = useEnv("HOST")
setValue("coder")

const args: UserProvidedArgs = {
host: "123.123.123.123",
}

const addr = {
host: "localhost",
port: 8080,
}

const actual = bindAddrFromArgs(addr, args)
const expected = {
host: "123.123.123.123",
port: 8080,
}

expect(actual).toStrictEqual(expected)
resetValue()
})

it("should use process.env.PORT if set", () => {
const [setValue, resetValue] = useEnv("PORT")
setValue("8000")
Expand Down