Coder Social home page Coder Social logo

node-tunnel's Introduction

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.

node-tunnel's People

Contributors

wrboyce avatar balena-ci avatar abresas avatar lekkas avatar page- avatar petrosagg avatar nazrhom avatar hedss avatar dfunckt avatar

Stargazers

Paulo Marinho avatar  avatar Vipul Gupta avatar  avatar Prashanta Shrestha avatar Anthony avatar Igor Macedo Quintanilha avatar Marcus S. Abildskov avatar Tiger Wang avatar  avatar Jonas Hauquier avatar Brad Pillow avatar Scott Ivey avatar Ayase Minori avatar Santosh Shrestha avatar Evan Owens avatar Danilo Pedrosa avatar Michal Bernhard avatar vulcanoIO - Open Source Sandbox and RE malwares avatar

Watchers

 avatar Marc Pous avatar Edwin Joassart avatar James Cloos avatar  avatar Jonathan avatar cristidragomir97 avatar Bill Love avatar Michal Toman avatar  avatar Heath Raftery avatar  avatar Omolola Olamide avatar  avatar  avatar  avatar Chris R. Chapman avatar Florin Sarbu avatar Balena team avatar Otávio Jacobi avatar Jenkins CI avatar  avatar Hubot avatar John S. Tonello avatar  avatar

node-tunnel's Issues

Resin.io Public URL HTTP forwarding and WebSockets

Hi,

I am not sure if this is the most appropriate repo. This report is contextualised to the "Public URL" Action executed via the "Enable public URL for this device" checkbox in device control panel of the resin.io Dashboard.

The forwarding works great but I came across a scenario where WebSocket connection that functions correctly over a direct (LAN) connection to the device does not work when accessed over the URL exposed via resindevice.io.

I am using python with Flask and Flask-SocketIO driven by gevent and the issue is identical to that described in:

miguelgrinberg/Flask-SocketIO#39
abourget/gevent-socketio#29

Essentially, comes down to the configuration of the proxying server. Therefore, my question is - what is the architecture behind the public URL / resindevice.io and is it possible that there is a level of "proxying" / header transformation happening between the public access endpoint and the target device?

Thanks in advance.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.