-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathmiddleware.ts
38 lines (33 loc) · 1.12 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
import { NextResponse, NextRequest } from "next/server";
export function middleware(request: NextRequest) {
const pathname = request.nextUrl.pathname;
const host = request.nextUrl.host;
if (process.env.VERCEL_ENV !== "production") {
return NextResponse.next();
}
if (pathname.startsWith("/craft") && !host.includes("craft")) {
const newPathname = pathname.replace("/craft", "");
return NextResponse.redirect(
new URL(newPathname, "https://craft.mxkaske.dev")
);
}
if (pathname.startsWith("/brew") && !host.includes("brew")) {
const newPathname = pathname.replace("/brew", "");
return NextResponse.redirect(
new URL(newPathname, "https://brew.mxkaske.dev")
);
}
}
export const config = {
matcher: [
/*
* Match all request paths except for the ones starting with:
* - api (API routes)
* - assets (public assets)
* - _next/static (static files)
* - _next/image (image optimization files)
* - favicon.ico, sitemap.xml, robots.txt (metadata files)
*/
"/((?!api|assets|_next/static|_next/image|favicon.ico|sitemap.xml|robots.txt).*)",
],
};