Skip to main content
Version: v0.x

How is ProxiedRequest constructed?

How Proxyflare proxies requests

When Proxyflare runs a Route, it constructs the ProxiedRequest based on three parameters:

  1. Request["url"]
  2. Route["from.pattern"]
  3. Route["to.url"]

The general formula is:

ProxiedRequest["href"] =
Route["to.url"].origin +
(Request["url.pathname"] +
(Route["to.url"].pathname - Route["from.pattern"].pathname))
Request["href"]Route["from.pattern"]Route["to.url"]ProxiedRequest["href"]
https://ex.com/apiex.com/*proxied.comhttps://proxied.com/api
https://ex.com/apiex.com/*proxied.com/apihttps://proxied.com/api/api
https://ex.com/apiex.com/api/*proxied.comhttps://proxied.com
https://ex.com/apiex.com/api/*proxied.com/apihttps://proxied.com/api

Setting stripFromPath to modify ProxiedRequest

Depending on your requirements, you might want to include the pathname of Route["from.pattern"] in the ProxiedRequest. To do this, set stripFromPath: false on your Route.

functions/_middleware.ts
const routes: Route[] = [
{
from: { pattern: "proxyflare.works/api/*", stripFromPath: false },
...
}
]

The table below demonstrates how stripFromPath: false modifies a ProxiedRequest.

Request["href"]Route["from.pattern"]Route["to.url"]ProxiedRequest["href"]
https://ex.com/apiex.com/*proxied.comhttps://proxied.com/api
https://ex.com/apiex.com/*proxied.com/apihttps://proxied.com/api/api
https://ex.com/apiex.com/api/*proxied.comhttps://proxied.com/api
https://ex.com/apiex.com/api/*proxied.com/apihttps://proxied.com/api/api
Tip

Set the Configuration["global.debug"] flag to attach a x-proxyflare-proxied-pathname response header to matched requests. This debug header contains the matched pathname.