How n8n-io/localtunnel works
Project type and purpose
• This is a Node.js-based CLI tool *and* library (“localtunnel”) whose job is to expose a local HTTP(S) endpoint to the internet by opening a tunnel through an upstream proxy server. Users invoke it as a global CLI (lt) or import it as a module (localtunnel(port, options)) in their own scripts.
File structure
• Top-level files (package.json, localtunnel.js) and configs (.eslintrc.js, .travis.yml, etc.) set up the CLI and build/test environment.
• lib/ contains three core modules:
• Tunnel.js – encapsulates a single tunnel connection (EventEmitter, handles socket setup and data piping).
• TunnelCluster.js – manages one or more Tunnel instances, handles reconnection logic if the local server restarts or the socket drops.
• HeaderHostTransformer.js – a small transform stream that rewrites HTTP Host headers to match the requested --local-host or default “localhost.”
• localtunnel.js is the main entry point for both CLI and programmatic API.
• localtunnel.spec.js holds unit tests.
• index.d.ts provides TypeScript typings for the API.
README for additional insights
• Confirms a dual-mode interface (CLI vs. JS API).
• Describes the lifecycle: connect to upstream proxy, negotiate a subdomain, pipe remote requests to the local port, emit events on request/error/close.
• Mentions TLS/HTTP options and environment variable overrides.
Detail checklist
• Where Host header rewriting happens (inside HeaderHostTransformer)
• Call out optional TLS config for local HTTPS tunnels