@inutil-labs/node-red-cloudflare-tunnels 0.0.5
Node-RED node to create cloudflare tunnels using cloudflared
Node-RED Cloudflare Tunnels
Overview
This Node-RED node allows you to easily create and manage secure Cloudflare tunnels directly from your Node-RED flows using the cloudflared
binary. With this node, you can expose local services to the internet securely, always using a valid SSL certificate, without complex network configurations.
Features
- Creates Cloudflare tunnels directly from Node-RED.
- Automatically manages tunnels to prevent redundant or failed tunnels.
- Outputs the public URL generated by Cloudflare for accessing your local service.
- Stores tunnel information in the global context of Node-RED for easy management and monitoring.
Installation
The easiest way to get started is by adding the node from the Palette.
However, you can also install it manually. To install the @inutil-labs/node-red-cloudflare-tunnels
node in your Node-RED setup, run the following command:
npm install @inutil-labs/node-red-cloudflare-tunnels
Note: Version 0.0.5 includes several bug fixes and improvements. It's recommended to update to this version if you're using an older one.
Usage
Once installed, you can use the node in your Node-RED flow by adding a cloudflared
node, found under the Network category. The node offers three modes of operation, configurable via its settings:
1. Test Mode (Default)
In this mode, the tunnel is established in a testing environment. No local URL is exposed, and instead, a default page is displayed to indicate whether the tunnel has been successfully established. This mode corresponds to the "hello-world" example from the Cloudflare Developers documentation.
2. Quick Tunnel Mode
This is the most commonly used mode for scenarios where you do not have your own domain managed in a Cloudflare account. In this mode, the local URL defined in the node configuration is exposed through a temporary public URL provided by Cloudflare. This allows quick and straightforward access to local services without the need for additional configuration. This mode uses Quick-Tunnels.
3. Managed Tunnel Mode
In this mode, you can establish a tunnel using a token from your Cloudflare account. This mode is intended for users with their own domain hosted on Cloudflare. The local URLs and their associated public URLs are defined and managed through the Cloudflare user interface. A token is required to enable this mode, you can get details on how to get the token on Cloudflare Developers.
Input
- The node doesn't require specific input to trigger the tunnel creation as it will automatically start a Cloudflare tunnel once you click on the button; but if you need to, the tunnel can be started also injecting a valid payload as shown on the examples.
Output
The output of the node is an object sent via msg.payload
, structured as follows:
{
"tunnelCreated": "https://example.trycloudflare.com",
"localUrl": "http://localhost:1880"
}
Where:
tunnelCreated
: The public URL of the Cloudflare tunnel.localUrl
: The local URL of the service exposed through the tunnel (optional).
Example and Demo:
Here's an example of how to use the node in a flow:
- Click the button on the left of the node to connect the tunnel -or use an Inject node to trigger the
cloudflared
node, see the examples-. - The
cloudflared
node will create a tunnel and output the public URL tomsg.payload.tunnelCreated
. - You can use a Debug node to log the URL or use it for further processing in your flow.
Here's a recorded demo:
Configuration
The node has the following configurable options:
- Test: Indicates whether the tunnel is for testing purposes or not.
- Local URL: The local URL you want to expose (optional).
- Token: The managed tunnel token to use (optional).
- Node-RED Global Context: The node stores information about the tunnel in the Node-RED global context under the
tunnelList
key. If you want to learn how to get the list of all tunnels running saved on the global context read the examples.
License
MIT License. See LICENSE for more information.