Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juliosantos/543777 to your computer and use it in GitHub Desktop.
Save juliosantos/543777 to your computer and use it in GitHub Desktop.
So this works as a reference since I couldn't find a thorough enough guide on the whole Internet for a unix-averse person like myself.
A Facebook application runs on what they call the *canvas*, which is a hole punched on their layout where the content of a *callback URL* will be rendered. When a user makes a request to see the application, Facebook parses the request and makes its own request to the callback URL. This means that Facebook must be able to communicate with the server where the content is.
When developing on a laptop this is often an issue if the underlying network is not under your control (meaning you can't setup port forwarding on the NAT router). This sucks big time.
ssh tunneling to the rescue! All we need is a machine with a direct connection to the Internet somewhere on the cloud, such as a VPS. We tell Facebook that our callback URL is on that VPS, and we set up a tunneling scheme to ensure that all requests made to the VPS are automatically and seamlessly forwarded to our laptop through this tunnel.
The setup is pretty simple for a vanilla unix system: * edit /etc/ssh/sshd_config and make sure that both *GatewayPorts* and *PermitRootLogin* are set to *yes* (you might need to add this congif flags)
* reboot the ssh daemon with: sudo /etc/init.d/ssh restart
Now back to your laptop:
* establish the tunnel from your laptop with: ssh VPS_ADDRESS -NR *:REMOTEPORT/localhost/LOCALPORT
* set the canvas callback URL to VPS_ADDRESS:REMOTEPORT
If you're using Phusion Passenger, just go tho its System Preferences tab, select your application, and write the following on the *Aliases* box: ServerAlias VPS_ADDRESS. If you're not using Phusion Passenger, you're doing it wrong.
It works, bitches! If it doesn't, it's probably firewall configs - go and edit iptables, ain't it fun?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment