-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmiddleware.ts
38 lines (32 loc) · 1006 Bytes
/
middleware.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { type NextFetchEvent, type NextRequest } from "next/server";
import {
AppMiddleware,
LinkMiddleware,
RootMiddleware,
} from "./lib/middleware";
import { parse } from "./lib/utils";
const DASHBOARD_HOSTNAMES = new Set(process.env.DASHBOARD_HOSTNAMES.split(","));
export const config = {
matcher: [
/*
* Match all paths except for:
* 1. /api/ routes
* 2. /_next/ (Next.js internals)
* 3. /_proxy/ (special page for OG tags proxying)
* 4. /_static (inside /public)
* 5. /_vercel (Vercel internals)
* 6. /favicon.ico, /sitemap.xml, /robots.txt (static files)
*/
"/((?!api/|_next/|_proxy/|_static|_vercel|favicon.ico|sitemap.xml|robots.txt).*)",
],
};
export function middleware(req: NextRequest, ev: NextFetchEvent) {
const { domain, key } = parse(req);
if (DASHBOARD_HOSTNAMES.has(domain)) {
return AppMiddleware(req, ev);
}
if (key.length === 0) {
return RootMiddleware(req, ev);
}
return LinkMiddleware(req, ev);
}