Services like ngrok and localtunnel exist so you can (and I'm not very keen in describing this) put your localhost on the public web for access on a public URL. Localtunnel appears more popular.
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 mydomain.com
, and then have it such that a cli command like mydomain create-tunnel
will return me a unique URL 12345.mydomain.com
or whatever, and I can then access my localhost from that unique URL.
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).
If I try to think through it, I would maybe try searching for HTTP tunnels, which leads to the Tunneling protocol. 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.
But if I try and imagine what would happen.... The browser makes a request to the URL on mydomain.com
. 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.
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)?
Maybe I should be looking here :).