Sharing Your Local Rails App for Development and Testing with Ngrok

Madhusudhanan - Oct 10 - - Dev Community

Developing an application often involves testing on your own system or with dedicated tools. But what if you need to share your progress or test features with devices not on your network?

Enter Ngrok, a powerful tool for developers! Ngrok allows you to expose your local web server to the internet securely, creating temporary URLs accessible from any device.

This guide will show you how to set up Ngrok and use it with your Rails app, streamlining your development and testing workflow.

Step 1: Sign Up for Ngrok

Head over to the Ngrok platform and create an account. On the welcome page, you'll see options for different agent types (software used to interact with Ngrok).

Welcome dashboard

Step 2: Install Ngrok (Docker Method)

For this guide, we'll use the Docker agent. However, Ngrok offers various agent types. Choose the one that best suits your environment, and follow the installation instructions provided on the Ngrok dashboard.

Here's the Docker command to run Ngrok and expose your Rails app on port 80:

docker run --net=host -it -e NGROK_AUTHTOKEN=**** ngrok/ngrok:latest http 80
Enter fullscreen mode Exit fullscreen mode

Important Note: Replace "****" with your actual Ngrok auth token, which you can find in your Ngrok account dashboard.

Step 3: Ensure Firewall Permissions

Verify that your firewall allows incoming connections to the port your application is running on (usually port 80). Refer to the screenshot below for an example of firewall settings on macOS.

Firewall settings on mac

Step 4: Start Your Rails App & Configure Local Development

Launch your local Rails development server with the port mentioned in the Ngrok command output (usually port 80 in this case).

If you're using a local development environment, add the following line to your config.hosts file in config/environments/development.rb:

Ruby

config.hosts << '.ngrok-free.app'
Enter fullscreen mode Exit fullscreen mode

Sharing Your App

Voila! Now you have a temporary public URL provided by Ngrok. Share this URL with your collaborators or test it on any device with an internet connection.

Advanced Ngrok Features

Ngrok offers a variety of features beyond basic tunnelling. In a future post, we'll delve deeper into exploring the full potential of Ngrok!

Thanks for reading!

Additional Tips:

Ngrok offers a free plan with limitations. Upgrading to a paid plan unlocks additional features and extended tunnel durations.
For enhanced security, consider using Ngrok with authentication methods offered in their paid plans.
This guide should get you started with Ngrok and streamline the development and testing process for your Rails app. Feel free to share your experiences and ask any questions in the comments below!

. . .
Terabox Video Player