Rails Tunnel plugin
Today I wanted to show someone a preview of some code I was writing for my Rails application, however didn’t feel like doing al the cumbersome work to transfer the files to my webserver and launch the application from there. I’ve been working on some ruby on rails facebook code lately and used the reverse tunnel configuration to test it out.
I figured it was easy to have a reverse tunnel for more application and especially the one i wanted to quickly show my friend.
Perhaps a plugin is a bit of overkill for just a rake task but what the heck here it is.
In order to install the plugin in your rails app just run
$ ./script/plugin install http://svn.stevenkroon.com/plugins/tunnel
Now you should have access the specific tunnel rake tasks, you can run
$ rake -T
From your rails root, and discover new tunnel specific tasks.
rake tunnel:create_config # Create reverse tunnel default config
rake tunnel:start # Starts a reverse tunnel
rake tunnel:status # Check if reverse tunnel is running
First thing todo is to create the tunnel config file, the easiest way is to run the create_config rake tastk.
$ rake tunnel:create_config
Now you will have a config file called ./config/tunnel.yml, change this file according to your needs.
remote_user: steven
remote_host: rails.stevenkroon.com
remote_port: 9999
local_port: 3000
The remote_user should be your ssh login name on the remote_host. If you just change the remote_user and remote_host configs, the only thing left todo is.
$ rake tunnel:start
(in /Users/steven/svn/railstt)
* Tunneling rails.stevenkroon.com:9999 to 127.0.0.1:3000
* press ctrl-c to quit the tunnel
If you haven’t setup ssh authorization keys you will be prompted for the password of your remote_user. As the message states, a reverse tunnel on the remote_host on port remote_port is started, meaning that if you would connect against this url, in my case http://rails.stevenkroon.com:9999 you will get the output of whatever is running on 127.0.0.1:3000, in my case a ruby on rails project.
So if you launch your Rails application you can now see this application when going to the external hosts url.
Now this is just for quick test and should not be seen as a deployment for your rails app, just a easy way to have a external entry point into your application running on your localhost also this is needed when developing facebook application since the call back url need to point to your running application.

