0.0.5 • Published 11 months ago

@conn.lt/tunnel v0.0.5

Weekly downloads
-
License
MIT
Repository
bitbucket
Last release
11 months ago

@conn.lt/tunnel

@conn.lt/tunnel is a Node.js SDK that enables secure tunneling through conn.lt servers. It allows you to create reliable and secure tunnels for your applications, services, or IoT devices, even if they are behind firewalls or NATs. With this SDK, you can effortlessly establish HTTP and TCP tunnels to your Mac, PC, server, or IoT device. Designed for simplicity, it empowers developers to proxy HTTP and TCP traffic securely via an uplink server with minimal configuration.

The SDK currently supports both HTTP and TCP forwarding capabilities. For HTTP tunnels, our cloud proxy server automatically handles SSL/TLS termination (offloading), ensuring secure HTTPS connections without requiring any SSL configuration on your local server. This makes it easy to expose your local HTTP services with automatic HTTPS encryption.

All tunnels are encrypted, ensuring your data remains secure and private during transmission.

Installation

npm install @conn.lt/tunnel
yarn add @conn.lt/tunnel
pnpm add @conn.lt/tunnel

Getting Started

Example Usage

HTTP forwarding

With HTTP forwarding, you can add authentication, and custom headers for your requests, and our proxy server automatically handles HTTPS offloading to secure your HTTP sessions.

import { connect } from '@conn.lt/tunnel';

// Connect to the uplink server
const connection = await connect();
connection.on('close', () => {
  console.log('Connection closed');
});
console.log('Connected with ID:', connection.id);
// Forward local HTTP server traffic
const forwarder = await connection.forward(3000); // 'localhost:3000' is also supported.
forwarder.on('close', () => {
  console.log('Forwarder closed');
});
console.log('Forwarder URL:', forwarder.url); // returns https://xxx.conn.lt

console.log(
  `Connection closed with ID: ${connection.id} has total ${connection.forwarders.length} forwarders.`,
);

// Close the forwarder and connection
await forwarder.close();
await connection.close();

TCP forwarding

import { connect } from '@conn.lt/tunnel';

// Connect to the uplink server
const connection = await connect({ type: 'tcp' });
connection.on('close', () => {
  console.log('Connection closed');
});
console.log('Connected with ID:', connection.id);
// Forward to a TCP server in local network
const forwarder = await connection.forward(22); // 'localhost:22' is also supported.
forwarder.on('close', () => {
  console.log('Forwarder closed');
});
console.log('Forwarder URL:', forwarder.url); // returns tcp://xxx.conn.lt:yyyy

console.log(
  `Connection closed with ID: ${connection.id} has total ${connection.forwarders.length} forwarders.`,
);

TCP forwarding to another TCP server on local network

Both HTTP and TCP forwarders can point to another host on your local network. For example, you can forward traffic to 192.168.1.100:3000 for HTTP or 192.168.1.100:22 for TCP connections.

import { connect } from '@conn.lt/tunnel';

// Connect to the uplink server
const connection = await connect({ type: 'tcp' });
connection.on('close', () => {
  console.log('Connection closed');
});
console.log('Connected with ID:', connection.id);
// Forward to a TCP server in local network
const forwarder = await connection.forward('192.168.1.100:22');
forwarder.on('close', () => {
  console.log('Forwarder closed');
});
console.log('Forwarder URL:', forwarder.url); // returns tcp://xxx.conn.lt:yyyy

console.log(
  `Connection closed with ID: ${connection.id} has total ${connection.forwarders.length} forwarders.`,
);

Forwarding to reserved domain/port

To use custom permanent domains and ports, you must first obtain a token from the conn.lt dashboard and then use it in the connection options.

import { connect } from '@conn.lt/tunnel';

// Connect to the uplink server
const connection = await connect({ type: 'tcp', token: 'reserved-host-token' });
connection.on('close', () => {
  console.log('Connection closed');
});
console.log('Connected with ID:', connection.id);
// Forward to a TCP server in local network
const forwarder = await connection.forward('192.168.1.100:22');
forwarder.on('close', () => {
  console.log('Forwarder closed');
});
console.log('Forwarder URL:', forwarder.url); // returns tcp://reserved-host.conn.lt:reserved-port

console.log(
  `Connection closed with ID: ${connection.id} has total ${connection.forwarders.length} forwarders.`,
);

License

This work is licensed under MIT.

0.0.5

11 months ago

0.0.4

11 months ago

0.0.3

11 months ago

0.0.2

11 months ago

0.0.1

11 months ago