Skip to main content
Version: v0.x

How do Routes match requests?

Request matching basics

This article descibes how Proxyflare matches an incoming request to a Route in your Configuration using the concept of pathname score.

Let's test your intuition with a basic setup.

Proxyflare is installed on with the Configuration below and a request arrives — GET

Each Route matches the incoming request. Which Route does Proxyflare run?

// incoming request: GET

const routes: Route[] = [
from: { pattern: "*" },
from: { pattern: "*" },

The second route runs! But why?

Proxyflare sorts each Route by the pathname score of Route["from.pattern"]. The second route runs because it contains more pathname parts.

How pathname score works

If an incoming request matches multiple Routes, Proxyflare runs the Route with the higher pathname score. Every Route is assigned a pathname score using the value of Route["from.pattern"].

Assigning pathname depth

Pathname score increases with pathname depth. The more forward-slash / separated path slugs in Route["from.pattern"], the higher the rank.

For example, Route["from.pattern"] has a pathname depth of two with path slugs shallow and deeper.

Pathname depthPathname scoreRoute["from.pattern"]

Breaking pathname depth ties

Given two patterns with the same pathname depth, rank is allocated by last slug length. For example, given Route["from.pattern"] and Route["from.pattern"], the latter wins because deeper is longer slug than deep.

Pathname depthLast slug lengthPathname scoreRoute["from.pattern"]

Proxyflare supports wildcard patterns for matching subrequests on a particular pathname. Some pathname patterns would be identical when wildcards are removed. In this case, pattern type is used to break the tie:

  1. Absolute path
  2. Inline wildcard*
  3. Slash wildcard*
Pathname depthLast slug lengthPattern typePathname scoreRoute["from.pattern"]
17inline **
17slash **

In other words, if multiple Routes are identical after wildcards are removed, the absolute path outranks the inline wildcard and the inline wildcard outranks the slash wildcard.


The Route with the highest pathname depth wins.

If multiple routes have the same pathname depth, the longer last path slug wins.

If multiple routes have the same last path slug after removing wildcards, absolute paths beat inline wildcards and inline wildcards beat slash wildcards.

The following table shows this ranking strategy with complex Route["from.pattern"]s listed by pathname score. The last column shows an incoming request that would match each pattern.

Pathname scoreRoute["from.pattern"]Example Matching Request*********

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.