Local Development with ngrok
Develop cloud services locally by continuously forwarding real data from a Data Connector using ngrok.
Last updated
Was this helpful?
Develop cloud services locally by continuously forwarding real data from a Data Connector using ngrok.
Last updated
Was this helpful?
This guide looks at how ngrok can be used to create a local development environment for Data Connectors applications. In summary, the Data Connector is configured to forward events to an URL generated by ngrok, a free proxy that points all incoming traffic to a specified port on localhost where we can receive the events and quickly develop and debug our application,
Service Account Your User or Service Account must have the of Project Developer or higher.
Local Development It is assumed that you are familiar with the bare minimums of local development, like using a shell.
is a free proxy service that enables forwarding HTTPS traffic from a publicly accessible URL to a port on localhost.
Most package managers should contain ngrok. If not, see the .
Debian: apt install ngrok
Arch:
Mac: brew install --cask ngrok
Windows: The ngrok client binary can be found .
In your shell of choice, run the ngrok
command with the http
argument, followed by the port to which you want to forward incoming traffic.
Once the proxy has started, all traffic directed to the randomly generated HTTPS URL will be directed to the specified port on your localhost.
If you're using the free version of ngrok, your session will expire after two hours. To restart, rerun the command. Note that this changes the URL.
All modifications to the generated URL path is reflected on the localhost. This can be useful to know as some local development frameworks, such as the one used by Azure Functions, utilizes pathing.
Original
https://5a880278718b.ngrok.io -> http://localhost:3000
Added path
https://5a880278718b.ngrok.io/some/path -> http://localhost:3000/some/path
Endpoint URL
The generated HTTPS URL of the form https://5a880278718b.ngrok.io
as provided by ngrok.
Note that the HTTP URL will not be accepted by the Data Connector.
When forwarding Data Connector events to localhost using ngrok, if no response is given to the request, an 502 Bad Gateway
error will the thrown.
The following snippets implement a simple local server app that receives the Data Connector request, prints the content, and responds with a success message.
Install the necessary dependencies.
Copy the following snippet to a local file app.py
.
Start the local server by running flask run --port 3000
in your shell.
To continuously forward events to localhost, or use an existing one, setting the following configurations.
Our sensors emit events every or when touched. When developing an application locally, being able to emit events at will can be quite useful. Our Sensor Emulator lets you create an emulated device for which events can be sent using a click of a button in DT Studio or the REST API.
You can read about how to create and emit emulated events on our page.