Skip to content

Instantly share code, notes, and snippets.

@zzbo
Created June 22, 2018 07:39
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zzbo/e6dc65540c660d38c8a983bf213cd66b to your computer and use it in GitHub Desktop.
Save zzbo/e6dc65540c660d38c8a983bf213cd66b to your computer and use it in GitHub Desktop.
sequelize with tunnel-ssh
// sequelize config
var sequelize = new sequelize('database', 'user', 'pass', {
host: '127.0.0.1',
dialect: 'mysql',
port: 3306,
pool: {
max: 10,
min: 0,
idle: 20000
}
});
// tunnel config
var config = {
user:'user',
host:'sshhost',
port:22,
dsthost:'127.0.0.1',
dstport:3306,
srchost:'127.0.0.1',
srcport:3306,
localhost:'127.0.0.1',
localport: 3306,
privatekey: require('fs').readfilesync('/path/to/key')
};
var tunnel = require('tunnel-ssh');
// initiate tunnel
tunnel(config, function (error, server) {
//....
if(error) {
console.error(error);
} else {
console.log('server:', server);
// test sequelize connection
sequelize.authenticate().then(function(err) {
console.log('connection established');
}).catch(function(err) {
console.error('unable establish connection', err);
})
}
})
@nandhaepn
Copy link

var config = {
username:'user'
host:'sshhost',
port:22,
dstHost:'127.0.0.1',
dstPort:3306,
srcHost:'127.0.0.1',
srcPort:3306,
localHost:'127.0.0.1',
localPort: 3306,
privatekey: require('fs').readfilesync('/path/to/key')
};
we need to change in camel case like above and "user" to "username"

@kennyendowed
Copy link

not working for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment