Getting Started with Traffic Policy
Prerequisites
- ngrok Account - Ensure you have an active ngrok account.
- ngrok Agent - Download and install the ngrok agent for your operating system.
Step 1: Create a Traffic Policy
Create a custom traffic policy by saving the following YAML configuration as policy.yml
:
on_http_request:
- actions:
- type: custom-response
config:
content: "Hello, World!"
This policy will respond to each HTTP request with a simple “Hello, World!” message.
Step 2: Apply Your Traffic Policy
Run the agent, applying the traffic policy you saved in the previous step with the --traffic-policy-file
flag:
$ ngrok http 80 --traffic-policy-file policy.yml
This command starts an HTTP tunnel for port 80
, using the specified policy.yml
traffic policy 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 endpoint with a custom traffic policy using the ngrok agent.
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.