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.

What you’ll need

1. Edit your ngrok configuration file

Enter the following command into your terminal:
ngrok config edit
In your configuration file, add the following content to 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
                body: Hello, World!
This policy will respond to each HTTP request with “Hello, World!”
Your configuration file version must be set to 3.

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.

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 configuration file. To learn more about ngrok’s Traffic Policy and its capabilities, check out the following resources: