Integrate tunnel-ssh without wrapping your existing codebase
$ npm install --save inject-tunnel-ssh
The injector was build to support almost zero changes to your existing codebase.
In the following example explains the integration (well injection) based on a little mongojs app..
var db = require('mongojs')('tunneltest1.com/test');
db.test.findOne(console.log);
For some we now need a tunnel to connect to the server..
// ---- START INTEGRATION CODE -----
require('inject-tunnel-ssh')([{
dstPort: 27017,
host: 'tunneltest1.com',
username: 'root'
}]).on('error',console.log);
// ---- END INTEGRATION CODE -----
var db = require('mongojs')('tunneltest1.com/test');
db.test.findOne(console.log);
The injector is a module wrapping the native node "net.connection" function to inject the tunnel configuration.
You can use the same properties as you would use in tunnel-ssh but in form of an array, since you can setup as many host / port combinations as you want. If no localPort is provided, the injector will search for a free one. For more information about the configuration please refer to the tunnel-ssh package.
If you get stuck using the lib please raise an issue or wait until we write a better readme.. ;)
MIT © Christoph Hagenbrock