proxyFor

tcmts.cli.sync.proxyFor · #gix33wfp · term · runs anywhere

The proxy a request's path goes to, of proxies (the longest path that holds it), if any.

export function proxyFor<P extends { path: string }>(proxies: P[], url: string): P | undefined {
  const pathname = url.split("?")[0]!;
  return proxies
    .filter((p) => pathname === p.path || pathname.startsWith(`${p.path}/`))
    .sort((a, b) => b.path.length - a.path.length)[0];
}

used by