Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

⚡️ perf: drop /api /trpc /webapi from proxy matcher (#16353)

Arvin Xu00dbd3356785
diff --git a/src/proxy.ts b/src/proxy.ts
index 76b6d412488..3ed15c8e524 100644
--- a/src/proxy.ts
+++ b/src/proxy.ts
@@ -5,8 +5,14 @@ const { middleware } = defineConfig();
// required to be literal
export const config = {
matcher: [
- // include any files in the api or trpc folders that might have an extension
- '/(api|trpc|webapi)(.*)',
+ // NOTE: `/api`, `/trpc`, `/webapi` are intentionally NOT matched. The
+ // middleware is a no-op for them — `defaultMiddleware` short-circuits the
+ // rewrite half via `backendApiEndpoints`, and they're all public routes, so
+ // the better-auth session lookup is skipped. Auth lives in the route
+ // handlers (`checkAuth`, trpc `protectedProcedure`), which return JSON 401s
+ // rather than the HTML redirect-to-signin. Skipping the matcher avoids a
+ // needless middleware invocation on the hottest backend traffic. (/oidc and
+ // /oauth stay matched below — their middleware pass is still load-bearing.)
// include the /
'/',
'/community',