<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

  <title><![CDATA[walkah]]></title>
  <link href="http://walkah.net/atom.xml" rel="self"/>
  <link href="http://walkah.net/"/>
  <updated>2012-04-13T16:54:16-04:00</updated>
  <id>http://walkah.net/</id>
  <author>
    <name><![CDATA[James Walker]]></name>
    
  </author>

  
  <entry>
    <title type="html"><![CDATA[Local development for external APIs]]></title>
    <link href="http://walkah.net/blog/walkah/local-development-external-apis"/>
    <updated>2010-08-20T00:00:00-04:00</updated>
    <id>http://walkah.net/blog/walkah/local-development-for-external-apis</id>
    <content type="html"><![CDATA[<p>Lately I have found myself doing a <em>lot</em> of development against external APIs, several of which require those services to be able to access my dev site directly. Traditionally, I've set up my dev sites on a public server (usually my personal VPS), mirrored the site locally, and used <a href="http://www.samba.org/rsync/">rsync</a> to push incremental changes from my local machine to the server.</p>

<p>This is a pain for two reasons:</p>

<ol>
<li>It means I have an extra step (to rsync) after each change. Yes, it's the same command over and over, but it gets repetitive. Also, if I forget, I spend a few minutes trying to figure out why the change I just made doesn't appear.</li>
<li>I'm also left with old dev sites (that I generally forget about) out on the public web - generally not getting proper attention for security updates, etc. This leaves my VPS open to attack.</li>
</ol>


<p>I also spend a <em>lot</em> of time tweaking my local environment to be just-how-I-like-it(tm).</p>

<p>Recently, I had an idea that, in hindsight, seems obvious. However, in talking with a few people, it seemed just novel enough to warrant the high bar of intellect that is a blog post. So here is the magic:</p>

<h3>What you need:</h3>

<ul>
<li>A wildcard DNS entry (i.e. <code>*.home.example.com</code>). I'm lucky that my <a href="http://teksavvy.com/">home ISP</a> allows me to have a static IP address, but a <a href="http://www.dyndns.com/">DynDNS</a> or similar account would also work.</li>
<li>A linux/mac computer attached to your home/office network that is <em>not</em> currently running a web server (i.e. port 80 is unused) - preferably connected via ethernet. I happen to have an old mac mini that serves as my "media server" at home that I'm using.</li>
<li>Ports 22 and 80 forwarded from your router to the aforementioned computer. (This is left as an exercise to the reader).</li>
</ul>


<h3>The "magic":</h3>

<p>Given the above, the rest is really quite simple (and perhaps obvious to some). A simple ssh port forward does the trick. Here's the command I use:</p>

<pre><code>ssh root@home.example.com -R 80:localhost:80
</code></pre>

<p>For the unfamiliar, that says ssh into home.example.com as root and send all the traffic coming to port 80 at home to port 80 on my localhost.</p>

<p>Voila! Now all requests to home.example.com will come to my local server and I can setup vhosts, etc accordingly. Also, if I just end my ssh connection, I no longer have to worry about the big, scary Internet accessing my dev sites.</p>

<h3>TODO</h3>

<p>I'm not 100% happy about allowing root ssh into my home network, so I may spend a rainy Sunday afternoon and setup an HTTP proxy at home that forwards to something like 8080 on localhost (and perhaps gives a nice "we're not home" message if I'm not ssh'ed in). That way, I wouldn't need to ssh in as root (which is necessary to bind the "low number" port).</p>

<p>If you do much tinkering with remote services (particularly OAuth-based services or webhooks, etc.), I hope this makes life just a little bit easier for you.</p>
]]></content>
  </entry>
  
</feed>

