Often while working on projects, a team member may ask you to share your local Sitecore instance with them. Or you might even want to expose your local site to an external service for performance testing/analysis. There is a handy dandy tool that makes this really easy, ngrok. Using secure tunnels ngrok exposes local sites behind NATs and firewalls to the public internet. By connecting to the ngrok cloud service which accepts traffic on a public address and relays that traffic through to the ngrok process running on your machine and then on to the local address you specify.
There are various plans available including a free plan which supports:
- HTTP/TCP tunnels on random URLs/ports
- 1 online ngrok process
- 4 tunnels/ngrok process
- 40 connections / minute
- Sign up for a free account.
- Download and run ngrok.exe.
- You must specify your authtoken to ngrok so that your client is tied to this account. Login to your account and grab your authtoken from the dashboard then run the following command: ngrok authtoken [your authtoken] This is saved in ~/.ngrok2/ngrok.yml so that you don’t need to repeat this step.
- When forwarding to a local port, ngrok does not modify the tunneled HTTP requests at all, they are copied to your server byte-for-byte as they are received. However, ngrok can rewrite your requests with a modified Host header. Use the -host-header switch to rewrite incoming HTTP requests, for example the following command will tunnel to my local Sitecore sandbox instance: ngrok http -host-header=rewrite http://sandbox.sitecore.local:80
- ngrok will assign you a unique public address while it is running:
Some Cool Features
- Inspect Traffic – ngrok provides a real-time web UI where you can introspect all of the HTTP traffic running over your tunnels. After you’ve started ngrok, just open http://localhost:4040 in a web browser to inspect request details.
- Replay Requests – ngrok allows you to replay any request with a single click dramatically speeding up your iteration cycle. Click the Replay button at the top-right corner of any request on the web inspection UI to replay it.
- Status Page – ngrok’s local web interface has a dedicated status page that shows configuration and metrics information about the running ngrok process. You can access it at http://localhost:4040/status.
- Password protect tunnel – You can make your tunnels secure with the -auth switch. This enforces HTTP Basic Auth on all requests with the username and password you specify as an argument.
- Serve local directories – Often our front end developers will work on static HTML templates on their file system. Well, ngrok has a built-in file server so you can serve local file system directories. So they could easily share these if they had a need to.