-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #57 from ikepu-tp/main
add host config
- Loading branch information
Showing
7 changed files
with
72 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { AddressInfo } from "net"; | ||
import { getUrlAddress } from "./getUrlAddress"; | ||
|
||
describe("getUrlAddress", () => { | ||
describe("when null is passed", () => { | ||
it("returns null", () => { | ||
const url = getUrlAddress(null); | ||
expect(url).toBeNull(); | ||
}); | ||
}); | ||
|
||
describe("when string is passed", () => { | ||
it("returns null", () => { | ||
const url = getUrlAddress("foobar"); | ||
expect(url).toBeNull(); | ||
}); | ||
}); | ||
|
||
describe("when IPv4 is passed", () => { | ||
it("returns correct url", () => { | ||
const address: AddressInfo = { | ||
address: "0.0.0.0", | ||
family: "IPv4", | ||
port: 8888, | ||
}; | ||
const url = getUrlAddress(address); | ||
expect(url).toEqual(`http://${address.address}:${address.port}`); | ||
}); | ||
}); | ||
|
||
describe("when IPv6 is passed", () => { | ||
it("returns correct url", () => { | ||
const address: AddressInfo = { | ||
address: "::", | ||
family: "IPv6", | ||
port: 8888, | ||
}; | ||
const url = getUrlAddress(address); | ||
expect(url).toEqual(`http://[${address.address}]:${address.port}`); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { AddressInfo } from "net"; | ||
|
||
export const getUrlAddress = (address: string | AddressInfo | null) => { | ||
if (!address || typeof address === "string") return null; | ||
|
||
if (["IPv4", "IPv6"].indexOf(address.family) === -1) | ||
throw new Error("Unknown address family"); | ||
|
||
return `http://${ | ||
address.family === "IPv4" ? address.address : `[${address.address}]` | ||
}:${address.port}`; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters