Using SSH tunnelling to run a Facebook application on your laptop

December 11, 2008 Link to post  Permalink

Why on earth would I want to run a Facebook application on my laptop? Surely these apps are meant to be used by lots of users and they shouldn’t stop running when I turn my computer off!

The only reason you’ll need to do this is during development. I run my apps on my laptop, behind a firewall, either at home, or on the road – so my IP address isn’t static. This allows me to make changes locally and immediately test them out without needing to copy to a server.

For this technique, you do need to have access to a unix server of some sort that does have a static IP address (or a fixed DNS name) that allows you to create SSH tunnels. With SSH client access, this should be possible with the low end hosting providers. Dreamhost costs less than $10 per month.

Facebook Application Setup

  1. Create a new application with the callback url http://ip-address:15000/ and a name of my-app-name-development
  2. Set your application configuration to use the app key and secret from step 1 when running on your laptop
  3. Run your application locally on port 5000

SSH Tunnel setup

Now we setup to get the remote server machine to listen on port 15000 and forward requests to this machine on port 5000.

1ssh -p 22 -NT -g -R *:15000:127.0.0.1:5000 <user>@<server> -v

I add the -v parameter so I can see a verbose output. Sometimes it takes Facebook a few seconds to connect to the tunnel, and the verbose option will allow you to see that when it works.

I add this command to a tunnel script I have and anytime I want to test out my app, I fire up the tunnel, then my application code, then access it on Facebook to try it out. If I have internet access, I can work on my Facebook applications.

I don’t use Rails, how does this help me?

If you can run a web server on your laptop, you can use this technique. This is not a Rails specific solution. I’ve seen information on the web for forwarding SMTP ports for email servers.

Windows?

I run this on Windows using a copy of SSH that comes with cwRsync