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.
Settings for the ngrok configuration file. The following config will tunnel to localhost:5000.
proto: http - the protocol. The HTTP protocol covers both HTTP and HTTPS
subdomain: btf - available with the paid version of ngrok. Otherwise the subdomain will be random public URL
bind_tls - without this setting both HTTP and HTTPS will be available from ngrok
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 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
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.
Place 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.
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)".
Consider reading An Ngrok Tutorial and Primer by Daniel Miessler