Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I tunnel the NodeJS debugger through to a Vagrant box?

I'm trying to set up the WebStorm NodeJS debugger to connect to a NodeJS project hosted on a Vagrant box. I'm coming up with some difficulties.

If I tunnel into the server the traditional way (ie, via Terminal), it all works fine and I'm able to cURL to it, debug it via WebStorm etc.

    ssh -L 5858:127.0.0.1:5858  -N [email protected]

Once I'd gotten that working, I put the following into my Vagrantfile:

    config.vm.network :forwarded_port, guest: 5858, host: 5858

Unlike before, this still works on the Vagrant box but not on my local machine. When I cURL to it, I get the following error:

    curl: (56) Recv failure: Connection reset by peer

Does anyone have any ideas as to what I'm doing wrong? Is this even possible to configure through the Vagrantfile?

I want to do it through this so my team can connect their debuggers with zero configuration.

Thanks

like image 279
MrSimonEmms Avatar asked Oct 21 '22 08:10

MrSimonEmms


1 Answers

You could try using a provision shell script (tunnel.sh) which would create a remote port forwarding to your machine:

#!/bin/bash

# executed from 'vagrant'
ssh -R 5858:127.0.0.1:5858 me@my-machine

Actually you should put this script in the same folder than your Vagrantfile, and edit the Vagrantfile to add this lines:

Vagrant.configure("2") do |config|
    config.vm.provision "shell", path: "tunnel.sh"
end

This will make Vagrant execute this script every time you execute the command:

vagrant up

Or:

vagrant provision

When trying this, you should delete the port forwarding line in your Vagrantfile.

I didn't try the tunnel, but I actually use provision scripts to configure the vm when it starts, like copying public keys in authorized_keys and similar tasks.

like image 95
R.Sicart Avatar answered Oct 31 '22 19:10

R.Sicart