Edge Middleware Invocation
Unanswered
Tamaskan Dog posted this in #help-forum
Tamaskan DogOP
Hello!
Looking for some help understanding the middleware invocation usage, and how to reduce it.
I am on the Pro plan and have about 600k / 1 Million invocations made for my website for the current billing cycle.
I'm using middlware exclusively for clerk authentication, using their nextjs middleware provider.
I was under the impression that my config matcher would reduce my usage for middlware, but it seems like routes that are suppose to be ignored are still going through the middlware function, and counting towards my usage? Example.
The following config inside middleware.ts
When I hit
Should it STILL be hitting the middlware if the config matcher is setup to ignore it??
Looking for some help understanding the middleware invocation usage, and how to reduce it.
I am on the Pro plan and have about 600k / 1 Million invocations made for my website for the current billing cycle.
I'm using middlware exclusively for clerk authentication, using their nextjs middleware provider.
I was under the impression that my config matcher would reduce my usage for middlware, but it seems like routes that are suppose to be ignored are still going through the middlware function, and counting towards my usage? Example.
The following config inside middleware.ts
export const config = {
matcher: [
"/((?!public|static|_next|.+\\.[\\w]+$).*)",
"/",
"/(api|trpc)(.*)",
"/((?!api/showcase/analytics).*)",
],
};When I hit
/api/showcase/analytics the middlware function is still being hit within my middleware.tsimport { authMiddleware } from "@clerk/nextjs";
export default function middleware(request: NextRequest) {
console.log("Request for : ", request.nextUrl.pathname);
authMiddleware(
{ publicRoutes: (req) => true,
ignoredRoutes: ['/', '/showcase', '/showcase/(.*)', '/api/sync', '/api/showcase/analytics', '/api/showcase/analytics/(.*)', '/api/stripe/webhook'],
// debug: true,
});
return NextResponse.next();
}Should it STILL be hitting the middlware if the config matcher is setup to ignore it??
1 Reply
Toyger
but you have this
"/(api|trpc)(.*)", which include api route, I am not sure about nextjs priority list of this array, but probably you shouldn't have contractionary rules in matcher.