The ngrok Environment

Nextjournal is a great way to experiment with building services in the cloud. Ngrok makes it easy to expose localhost servers to the internet.
Install
curl -sS https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip -o ngrok.zipunzip /ngrok.zipConfigure
Settings for the ngrok configuration file. The following config will tunnel to localhost:5000.
regionusconsole_uitruetunnels btf protohttp addr5000 subdomainbtfproto: http- the protocol. The HTTP protocol covers both HTTP and HTTPSaddraddr: 5000- the port of the application.addr:https://localhost:5000use the full URL to force HTTPS (equivalent tongrok http https://localhost:5000on the command line)
subdomain: btf- available with the paid version of ngrok. Otherwise the subdomain will be random public URLbind_tls- without this setting both HTTP and HTTPS will be available from ngrokbind_tls: true- ngrok only listens on an HTTPS tunnel endpointbind_tls: false- ngrok only listens on an HTTP tunnel endpoint
host_header: localhost- some APIs will want to see the host header of your app rather than 'ngrok'
Grab your authtoken from ngrok, store the token in your Nextjournal secret vault, and add it to the environment. The token will authenticate this notebook with the ngrok service.
Prepend the authtoken to the configuration file above, ngrok.yml.
echo 'authtoken:' $ngrok | cat - ngrok.yml > /tmp/out && mv /tmp/out ngrok.ymlRun
Run ngrok in the background using nohup. Unfortunately, there are no plans to offer a daemon service in the basic Ngrok package.
Nohup stands for "No Hangup". The command ignores the HUP signal that terminates a process when a terminal connection is closed. A few notes on using nohup:
nohup command &:&run the command in the backgroundnohup command > /path/to/file.txt:>redirects the output from the defaultnohup.out
Nextjournal will display any stout beneath the running cell. Even with the process running in the background, the stdout will occupy the notebooks process unless it is redirected to a file. Therefore, &> is used below to redirect stout output to a file.
nohup /ngrok start --all --config="/ngrok.yml" &> /tmp/ngrok.log & sleep 1tail /tmp/ngrok.logPlace the URL into a browser and the tunnel will be visible. Anything served from port 5000 will appear here. In this case, there is nothing being served, hence the error message.

Admin
The service is up and running. To stop the ngrok tunnel, use the kill command with the process ID: kill <PID> or kill -9 "$(pgrep ngrok)".
ps aux# kill -9 "$(pgrep ngrok)"ps auxAppendix
Consider reading An Ngrok Tutorial and Primer by Daniel Miessler