Skip to content

Commit e2aa636

Browse files
authored
fix: config is statically analyzed, failing on build (calcom#25558)
1 parent d152811 commit e2aa636

1 file changed

Lines changed: 12 additions & 18 deletions

File tree

apps/api/v1/middleware.ts

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,19 @@
11
import type { NextRequest } from "next/server";
22
import { NextResponse } from "next/server";
33

4-
export const BLOCKED_ROUTE_SEGMENTS = ["_get", "_post", "_patch", "_delete", "_auth-middleware"] as const;
5-
6-
const pathContainsBlockedSegment = (pathname: string) =>
7-
pathname
8-
.split("/")
9-
.filter(Boolean)
10-
.some((segment) => BLOCKED_ROUTE_SEGMENTS.includes(segment as (typeof BLOCKED_ROUTE_SEGMENTS)[number]));
11-
12-
export function middleware(request: NextRequest) {
13-
if (pathContainsBlockedSegment(request.nextUrl.pathname)) {
14-
return NextResponse.json({ message: "Forbidden" }, { status: 403 });
15-
}
16-
17-
return NextResponse.next();
4+
export function middleware(_request: NextRequest) {
5+
// Matcher guarantees the last segment is one of the blocked segments, so we can
6+
// immediately return a 403 without further path checks.
7+
return NextResponse.json({ message: "Forbidden" }, { status: 403 });
188
}
199

2010
export const config = {
21-
matcher: BLOCKED_ROUTE_SEGMENTS.flatMap((segment) => [
22-
`/:path*/${segment}/:rest*`,
23-
`/:path*/${segment}`,
24-
]),
11+
// The blocked segment is always the last part of the path, so we only need this matcher.
12+
matcher: [
13+
"/:path*/_get",
14+
"/:path*/_post",
15+
"/:path*/_patch",
16+
"/:path*/_delete",
17+
"/:path*/_auth-middleware",
18+
],
2519
};

0 commit comments

Comments
 (0)