Skip to content

Commit

Permalink
allow forward config to use a string port
Browse files Browse the repository at this point in the history
  • Loading branch information
bobzilladev committed Mar 14, 2024
1 parent cc40296 commit 2a5ae73
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
14 changes: 13 additions & 1 deletion __test__/connect.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ test("forward number", async (t) => {
await validateShutdown(t, httpServer, url);
});

test("forward port string", async (t) => {
test("forward just string as port", async (t) => {
ngrok.consoleLog();
const httpServer = await makeHttp();
ngrok.authtoken(process.env["NGROK_AUTHTOKEN"]);
Expand All @@ -166,6 +166,18 @@ test("forward addr port string", async (t) => {
await validateShutdown(t, httpServer, url);
});

test("forward port string", async (t) => {
ngrok.consoleLog();
const httpServer = await makeHttp();
ngrok.authtoken(process.env["NGROK_AUTHTOKEN"]);
const listener = await ngrok.forward({ port: httpServer.listenTo.split(":")[1] });
const url = listener.url();

t.truthy(url);
t.truthy(url.startsWith("https://"), url);
await validateShutdown(t, httpServer, url);
});

test("forward string", async (t) => {
const httpServer = await makeHttp();
ngrok.authtoken(process.env["NGROK_AUTHTOKEN"]);
Expand Down
7 changes: 7 additions & 0 deletions index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions trailer.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,13 @@ async function ngrokForward(config) {
}
config = { addr: address };
}
if (typeof config["port"] === "string" || config["port"] instanceof String) {
const num = parseInt(config["port"]);
if (isNaN(num)) {
throw new Error(`port must be a number: '${config["port"]}'`);
}
config["port"] = num;
}
// Convert addr to string to allow for numeric port numbers
const addr = config["addr"];
if (Number.isInteger(addr)) config["addr"] = "localhost:" + String(config["addr"]);
Expand Down

0 comments on commit 2a5ae73

Please sign in to comment.