Skip to content
18 changes: 18 additions & 0 deletions docs/http/traffic-policy/gallery.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
Deny,
DeprecateVersion,
EnforceTLS,
ForwardInternalFull,
JWTsRateLimiting,
LimitSize,
LogUnsuccessful,
Expand Down Expand Up @@ -156,3 +157,20 @@ Prevent obsolete and potentially vulnerable browsers, SDKs, or CLI tools like `c
Connect your API to ngrok's [event logging system](/docs/obs/index.mdx) for smarter troubleshooting of your API gateway and upstream services.

<LogUnsuccessful />

### Routing requests based on request path

You can route traffic from one domain to multiple services (ports) based on the path sent in each request.

In your Agent [configuration file](/docs/agent/config/), you can modify both the [forwardInternal](/docs/http/traffic-policy/actions/forward-internal/) and
[URL Rewrite](/docs/http/traffic-policy/actions/url-rewrite/) Traffic Policy Actions to route requests to different upstream ports based on the URL path. For example you may want to route public traffic to a URL such as `https://mypublic.ngrok.app/...` to `http://localhost:80/...`.

The following example:

- Creates a public endpoint using an ngrok reserved domain – "mypublic.ngrok.app"
- Create an internal endpoint – "service1.internal"
- Uses the `forwardInternal` action to forward requests that have `/service1` in the path to a different port.
- Removes the added path from the request before sending it to the upstream service using the URL Rewrite action.
- This path does not have to exist on the upstream service, as a virtual `service1` path will exist on the public ngrok endpoint.

<ForwardInternalFull />
58 changes: 58 additions & 0 deletions traffic-policy/gallery.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -601,4 +601,62 @@ export const OIDCIdentityToken = () => (
/>
);

export const ForwardInternalFull = () => (
<ConfigExample
config={{
version: "3",
agent: {
authtoken: "your-authtoken",
},
endpoints: [
{
name: "httpexample",
url: "https://mypublic.ngrok.app",
upstream: {
url: "localhost:80",
},
traffic_policy: {
on_http_request: [
{
expressions: ["req.url.path.startsWith('/service1')"],
actions: [
{
type: "forward-internal",
config: {
url: "https://service1.internal:443",
},
},
],
},
],
},
},
{
name: "example-internal-1",
url: "service1.internal",
upstream: {
url: "localhost:81",
},
traffic_policy: {
on_http_request: [
{
expressions: ["req.url.path.startsWith('/service1')"],
actions: [
{
type: "url-rewrite",
config: {
from: "/service1/?([.*]+)?",
to: "/$1",
},
},
],
},
],
},
},
],
}}
/>
);

;
Loading