Skip to content

Commit a76e524

Browse files
authored
Add "CODE_SERVER_HOST" environment variable (#6423)
1 parent 913fc30 commit a76e524

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

src/node/cli.ts

+3
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,9 @@ export function bindAddrFromArgs(addr: Addr, args: UserProvidedArgs): Addr {
732732
if (args["bind-addr"]) {
733733
addr = parseBindAddr(args["bind-addr"])
734734
}
735+
if (process.env.CODE_SERVER_HOST) {
736+
addr.host = process.env.CODE_SERVER_HOST
737+
}
735738
if (args.host) {
736739
addr.host = args.host
737740
}

test/unit/node/cli.test.ts

+44
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,50 @@ describe("bindAddrFromArgs", () => {
789789
expect(actual).toStrictEqual(expected)
790790
})
791791

792+
it("should use process.env.CODE_SERVER_HOST if set", () => {
793+
const [setValue, resetValue] = useEnv("CODE_SERVER_HOST")
794+
setValue("coder")
795+
796+
const args: UserProvidedArgs = {}
797+
798+
const addr = {
799+
host: "localhost",
800+
port: 8080,
801+
}
802+
803+
const actual = bindAddrFromArgs(addr, args)
804+
const expected = {
805+
host: "coder",
806+
port: 8080,
807+
}
808+
809+
expect(actual).toStrictEqual(expected)
810+
resetValue()
811+
})
812+
813+
it("should use the args.host over process.env.CODE_SERVER_HOST if both set", () => {
814+
const [setValue, resetValue] = useEnv("CODE_SERVER_HOST")
815+
setValue("coder")
816+
817+
const args: UserProvidedArgs = {
818+
host: "123.123.123.123",
819+
}
820+
821+
const addr = {
822+
host: "localhost",
823+
port: 8080,
824+
}
825+
826+
const actual = bindAddrFromArgs(addr, args)
827+
const expected = {
828+
host: "123.123.123.123",
829+
port: 8080,
830+
}
831+
832+
expect(actual).toStrictEqual(expected)
833+
resetValue()
834+
})
835+
792836
it("should use process.env.PORT if set", () => {
793837
const [setValue, resetValue] = useEnv("PORT")
794838
setValue("8000")

0 commit comments

Comments
 (0)