npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-tunnel

v4.0.1

Published

Http tunneling proxy

Downloads

2,432

Readme

node-tunnel

npm version dependencies

HTTP tunneling proxy library.

Installation

Install node-tunnel by running:

$ npm install node-tunnel

Documentation

Tunnel

Tunnel.connect(port, host, client, req)

Function that creates a connection between the tunnel and the target server. It defaults to Promise.method(net.connect) which returns Promise<net.Socket>.

Kind: method of Tunnel
Summary: Establish the upstream connection.
Access: public

Example

// Create a tunnel with a custom connect method
tunnel = new Tunnel();
tunnel.connect = (port, host, client, req) => {
  console.log(`Establishing tunnel to ${host}:${port}...`);
  return Promise.method(net.connect);
};

Tunnel.use( function(req, cltSocket, head, next) )

Use a middleware function for rewriting request destination (by changing req.url), add authorization or filter connections to only certain hosts and ports.

The parameters are the same as the http module passes on "connect" event, plus a callback function similar to express middleware.

Keep in mind that express middleware do not work with in conjunction with this module.

Kind: method of Tunnel
Summary: Use a middleware.
Access: public

Example

// Start a tunneling proxy on port 3128
tunnel = new Tunnel();
tunnel.use( function(req, cltSocket, head, next) {
	// Send all connections to port 80 of localhost.
	req.url = "http://localhost:80";
	next();
} );
tunnel.listen(3128)

Tunnel.listen(port, [cb])

Start listening on the given port. An optional callback function is called when tunnel is ready to listen.

Kind: method of Tunnel
Summary: Start listening.
Access: public
Example

tunnel = new Tunnel();
tunnel.listen(3128, function() {
	console.log("Tunnel listening on port 3128");
});

basicAuth(req, cltSocket, head, next)

Parses Proxy-Authorization header and sets req.auth.username and req.auth.password properties.

Further middleware should be added to accept or reject connections based on this authentication information. Kind: method of Tunnel Summary: Parse Proxy-Authorization header. Access: public
Example

tunnel = new Tunnel();
tunnel.use(basicAuth);
tunnel.use( function(req, cltSocket, head, next) {
	if (req.auth.username != "user" || req.auth.password != "password") {
		cltSocket.end() // close connection
		return; // no further middleware need to be called
	}
	next();
} );
tunnel.listen(3128, function() {
	console.log("Tunnel listening on port 3128");
});

Support

If you're having any problem, please raise an issue on GitHub and the Balena team will be happy to help.

Tests

Run the test suite by doing:

$ npm install && npm test

Contribute

Before submitting a PR, please make sure that you include tests, and that coffeelint runs without any warning:

License

The project is licensed under the MIT license.