Running Heroku Apps Locally on Port 80, with Facebook Connect


Suppose you are hosting your app on Heroku or some similar provider, and you rely on Facebook Connect for user authentication. How do you run your app locally so that you can develop and test without messing with the live version?

Using a third party API like Facebook Connect makes it tricky because you need to specify a URL on your Facebook app, and it either needs to be localhost or your live domain, like app.herokuapp.com.

The solution:

1. sudo vim /etc/hosts and add a line like this

127.0.0.1    app.herokuapp.com

2. Your node/heroku app runs on port 3000, but the IP configured above will only work for port 80, the default for http. We need to redirect all 80 traffic to port 3000, with the command below.

sudo iptables -t nat -I OUTPUT -p tcp -d 127.0.0.1 --dport 80 -j REDIRECT --to-ports 3000

Notice that the above command works for local requests. If you have external traffic on the server, you need to run this other command:

sudo iptables -t nat -I PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 3000

That is it. Remember to use HTTP and not HTTPS locally as well, else you will get a browser warnings or an error.

Leave a Reply

Your email address will not be published. Required fields are marked *