- You can create a yaml or json file and manually apply it to specific endpoints when you start them. This approach is best when you want to apply a different Traffic Policy to each endpoint.
- You can edit your Agent Configuration File. This file applies to all endpoints you start with the agent CLI by default. Choose this approach to set up traffic management logic for all endpoints running locally on your machine.
What you’ll need
- An ngrok account.
- The ngrok Agent CLI installed.
1. Set up your Traffic Policy
- Using a separate policy file
- Using the Agent Configuration File
Create a custom Traffic Policy file with the following contents:This policy will respond to each HTTP request with a simple “Hello, World!” message.
2. Start your endpoint
- Using a separate policy file
- Using the Agent Configuration File
Run the agent, applying the Traffic Policy you saved in the previous step with the This command starts an HTTP tunnel for port
--traffic-policy-file flag:80, using the specified policy.yml Traffic Policy to manage traffic.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.What’s next?
You’ve now successfully set up your first Agent Endpoint with a custom Traffic Policy using the ngrok agent. To learn more about ngrok’s Traffic Policy and its capabilities, check out the following resources:- Learn how the Traffic Policy engine works under the hood.
- Check out the example gallery to see Traffic Policy in real-world scenarios.
- The list of available actions, macros and variables you can use.