From a57b36ed8dd7cfc74eded064909e23efc960719e Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Mon, 12 Apr 2021 14:07:03 -0500 Subject: [PATCH] Add Create A Public URL For A Local Server as a workflow til --- README.md | 3 +- .../create-a-public-url-for-a-local-server.md | 32 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 workflow/create-a-public-url-for-a-local-server.md diff --git a/README.md b/README.md index 1663d78..1343fe6 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ pairing with smart people at Hashrocket. For a steady stream of TILs, [sign up for my newsletter](https://tinyletter.com/jbranchaud). -_1111 TILs and counting..._ +_1112 TILs and counting..._ --- @@ -1290,6 +1290,7 @@ _1111 TILs and counting..._ - [Change Window Name In iTerm](workflow/change-window-name-in-iterm.md) - [Convert An ePub Document To PDF On Mac](workflow/convert-an-epub-document-to-pdf-on-mac.md) +- [Create A Public URL For A Local Server](workflow/create-a-public-url-for-a-local-server.md) - [Enable Dev Tools For Safari](workflow/enable-dev-tools-for-safari.md) - [Forward Stripe Events To Local Server](workflow/forward-stripe-events-to-local-server.md) - [Get Your Public IP Address](workflow/get-your-public-ip-address.md) diff --git a/workflow/create-a-public-url-for-a-local-server.md b/workflow/create-a-public-url-for-a-local-server.md new file mode 100644 index 0000000..443be00 --- /dev/null +++ b/workflow/create-a-public-url-for-a-local-server.md @@ -0,0 +1,32 @@ +# Create A Public URL For A Local Server + +At times while developing an app locally, you need to expose the local server +to the public internet. This can be useful and necessary when working on a +3rd-party integration or when you want to show what you have running locally to +someone else. + +In addition to tools like [ngrok](https://ngrok.com/), I've found the +[`localtunnel`](https://github.com/localtunnel/localtunnel) npm package to be +an effective way to quickly expose a localhost port. + +``` +$ npx localtunnel --port 3000 --subdomain some-custom-subdomain +your url is: https://some-custom-subdomain.loca.lt +``` + +This will create a `loca.lt` URL with the given subdomain that tunnels +requests to `localhost:3000`. If the `--subdomain` flag is not specified or +what you've specified isn't available, `localtunnel` will generate a random +subdomain. + +For the subdomain, I recommend using something sufficiently unique like +`josh-branchaud-04092021`. Using the date has the added benefit of +contextualizing when I generated the URL. + +In my experience, these are not long-lived domains. Sometimes the connection +gets interrupted and you'll have to restart it. Often when restarting, the +specified subdomain will then be flagged as unavailable, so you have to tweak +it a little. + +Because it is using `npx`, there is nothing to install as long as you already +have `node` itself installed.