-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmiddleware.ts
42 lines (37 loc) · 1.17 KB
/
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
39
40
41
42
import { NextFetchEvent, NextRequest, NextResponse } from "next/server";
import AppMiddleware from "@/lib/middleware/app";
import DomainMiddleware from "@/lib/middleware/domain";
export const config = {
matcher: [
/*
* Match all paths except for:
* 1. /api/ routes
* 2. /_next/ (Next.js internals)
* 3. /_proxy/, /_auth/ (special pages for OG tags proxying and password protection)
* 4. /_static (inside /public)
* 5. /_vercel (Vercel internals)
* 6. /favicon.ico, /sitemap.xml (static files)
*/
"/((?!api/|_next/|_proxy/|_auth/|_static|_vercel|favicon.ico|sitemap.xml).*)",
],
};
export default async function middleware(req: NextRequest, ev: NextFetchEvent) {
const path = req.nextUrl.pathname;
const host = req.headers.get('host');
if (
process.env.NODE_ENV !== "development" &&
!(host?.includes("papermark.io") || host?.endsWith(".vercel.app"))
) {
return DomainMiddleware(req);
}
if (
path !== "/" &&
path !== "/privacy" &&
!path.startsWith("/alternatives/") &&
!path.startsWith("/blog/") &&
!path.startsWith("/view/")
) {
return AppMiddleware(req);
}
return NextResponse.next();
}