Getting Started with Agent Endpoints and Traffic Policy via Configuration File
The following getting started guide will take you through starting an Agent Endpoint with a Traffic Policy applied via the Agent Configuration File. Note, this guide requires that your agent configuration file is set to v3.
Prerequisites
- ngrok Account - Ensure you have an active ngrok account.
- ngrok Agent - Download and install the ngrok agent for your operating system.
Step 1: Edit your ngrok Configuration File
Enter the following command into your terminal:
ngrok config edit
You should now be editing your configuration file, append the following content to your config file at the bottom and save the file:
endpoints:
- name: my-agent-endpoint
description: My first Agent Endpoint with a Traffic Policy
upstream:
url: 80
traffic_policy:
on_http_request:
- actions:
- type: custom-response
config:
status_code: 200
content: Hello, World!
This policy will respond to each HTTP request with a simple “Hello, World!” message.
Your configuration file version
must be set to 3
.
Step 2: Start your Agent Endpoint
Start your Agent Endpoint by running the following command:
ngrok start my-agent-endpoint
This command will start an HTTP tunnel for port 80
, using the specified traffic policy in the config file to manage traffic.
Step 3: Test it out
After running the ngrok command in the previous step you should now see a URL in the forwarding section. Open the URL in your web browser. You should see the "Hello, World!" message displayed in your browser.
Next Steps
🎉 Congratulations!
You've successfully set up your first Agent Endpoint with a custom Traffic Policy using the ngrok agent configuration file.
To learn more about ngrok's Traffic Policy and it's capabilities, check out the following resources:
- Learn about the core concepts like phases and rules.
- Check out the examples, use-cases and guides.
- The list of available actions, macros and variables you can use.