Skip to content

Instantly share code, notes, and snippets.

@zzbo
Created June 22, 2018 07:39
Show Gist options
  • 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);
})
}
})
@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