Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"HOST" environment variable #6423

Merged
merged 2 commits into from
Sep 8, 2023
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