Skip to content

Conversation

@ghost
Copy link

@ghost ghost commented Mar 25, 2025

Take it for a spin in your own project!

  1. Clone the repo and checkout this branch
  2. Run cargo build in the root directory
  3. Run yarn build in the root directory (generates a production version of the sdk as a node package)
  4. Copy the newly created *.node file into your own node project
  5. Start a server on whatever two ports you'd like (I use `python -m http.server 3000 && python -m http.server 8000)
  6. Open the url of your ngrok reserved domain in the browser
  7. Observe that both ports (3000 and 8000) show the http requests!

index.js

// Require ngrok javascript sdk
const ngrok = require("./ngrok.darwin-arm64.node");
// import ngrok from '@ngrok/ngrok' // if inside a module

(async function () {
  // Establish connectivity
  const builder = new ngrok.SessionBuilder().authtokenFromEnv();
  builder.connect().then((session) => {
    session
      .httpEndpoint()
      .domain("/* your domain */")
      .poolingEnabled(true)
      .listen()
      .then((listener) => {
        console.log(`Ingress established at: ${listener.url()}`);
        listener.forward("http://localhost:3000");
      });
  });
  builder.connect().then((session) => {
    session
      .httpEndpoint()
      .domain("/* your domain */")
      .poolingEnabled(true)
      .listen()
      .then((listener) => {
        console.log(`Ingress established at: ${listener.url()}`);
        listener.forward("http://localhost:8000");
      });
  });
})();

process.stdin.resume();

Copy link
Contributor

@bmpngrok bmpngrok left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@ghost ghost merged commit e274abc into main Mar 26, 2025
23 checks passed
@ghost ghost deleted the danielle/enable-endpoint-pooling branch March 26, 2025 20:33
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant