title: How to build a localtunnel / ngrok clone
body: <p>Services like <a href="https://ngrok.com/" rel="nofollow noreferrer">ngrok</a> and <a href="https://localtunnel.github.io/www/" rel="nofollow noreferrer">localtunnel</a> exist so you can (and I'm not very keen in describing this) <em>put your localhost on the public web for access on a public URL</em>. <a href="https://github.com/localtunnel/localtunnel" rel="nofollow noreferrer">Localtunnel</a> appears more popular.</p>
  
  <p>My question is, at a general level / high-level overview kind of thing, how do you implement this yourself? Like, how can I create a domain <code>mydomain.com</code>, and then have it such that a cli command like <code>mydomain create-tunnel</code> will return me a unique URL <code>12345.mydomain.com</code> or whatever, and I can then access my localhost from that unique URL.</p>
  
  <p>I know how to build CLIs and RESTful web apps, but I don't know where the connection is made between localhost and the public URL. I don't see how I can host my localhost on a public URL (https URLs only).</p>
  
  <p>If I try to think through it, I would maybe try searching for <a href="https://en.wikipedia.org/wiki/HTTP_tunnel" rel="nofollow noreferrer">HTTP tunnels</a>, which leads to the <a href="https://en.wikipedia.org/wiki/Tunneling_protocol" rel="nofollow noreferrer">Tunneling protocol</a>. The HTTP tunnels page doesn't reveal too much. The tunneling protocol page goes too low level I think, I think I'm asking about a higher level.</p>
  
  <p>But if I try and imagine what would happen.... The browser makes a request to the URL on <code>mydomain.com</code>. This then has an already open HTTPS connection with an HTTPS server on my local machine. It proxies the request to the local machine's HTTPS server. This then makes a request to localhost. That is, it proxies the request from the local HTTPS server to whatever localhost server I'm actually concentrated on. It makes the request to the localhost server, then gets a response. Pipes the response back to the remote machine, then that remote machine pipes it back to the browser.</p>
  
  <p>Also, is there anything I need to worry about in terms of security (both in terms of building a secure tunneling app, and also in terms of how you bypass the firewalls so to speak using something like this)?</p>
  
  <p>Maybe I should be looking <a href="https://github.com/localtunnel/server" rel="nofollow noreferrer">here</a> :).</p>