Skip to content

Commit

Permalink
respect input hostname for generating default url
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Aug 27, 2023
1 parent 67b263b commit 89c66a1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ export function generateURL(
) {
port = "";
}

Check warning on line 64 in src/_utils.ts

View check run for this annotation

Codecov / codecov/patch

src/_utils.ts#L63-L64

Added lines #L63 - L64 were not covered by tests
if (hostname.includes(":")) {
hostname = `[${hostname}]`;
}

Check warning on line 67 in src/_utils.ts

View check run for this annotation

Codecov / codecov/patch

src/_utils.ts#L66-L67

Added lines #L66 - L67 were not covered by tests
return (
proto + hostname + ":" + port + (baseURL || listhenOptions.baseURL || "")
);
Expand Down
7 changes: 5 additions & 2 deletions src/listen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export async function listen(
}

// --- GetURL Utility ---
const getURL = (host = "localhost", baseURL?: string) =>
const getURL = (host = listhenOptions.hostname, baseURL?: string) =>
generateURL(host, listhenOptions, baseURL);

// --- Start Tunnel ---
Expand Down Expand Up @@ -174,7 +174,10 @@ export async function listen(

// Add localhost URL
if (_localhost || _anyhost) {
_addURL("local", getURL("localhost", getURLOptions.baseURL));
_addURL(
"local",
getURL(listhenOptions.hostname || "localhost", getURLOptions.baseURL),
);
}

// Add tunnel URL
Expand Down
1 change: 1 addition & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ describe("listhen", () => {
describe("port", () => {
test("pass hostname to get-port-please", async () => {
listener = await listen(handle, { hostname: "127.0.0.1" });
console.log(listener.url);
expect(listener.url.startsWith("http://127.0.0.1")).toBe(true);
});

Expand Down

0 comments on commit 89c66a1

Please sign in to comment.