forked from magicuidesign/magicui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
middleware.ts
39 lines (32 loc) · 1.06 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
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";
export const config = {
matcher: ["/((?!_next|api|[\\w-]+\\.\\w+).*)"],
};
export default async function middleware(req: NextRequest) {
const engyneSubdomain = "magicui"; // change this to your Engyne subdomain
const url = req.nextUrl.clone();
const { pathname } = req.nextUrl;
const hostname = req.headers.get("host");
if (!hostname)
return new Response(null, {
status: 400,
statusText: "No hostname found in request headers",
});
if (pathname === "/engyne-sitemap.xml") {
return NextResponse.rewrite(
new URL(pathname, `https://${engyneSubdomain}.engyne.page`),
);
}
if (pathname.startsWith("/blog") || pathname.startsWith("/tags")) {
return NextResponse.rewrite(
new URL(pathname, `https://${engyneSubdomain}.engyne.page`),
);
}
if (pathname.startsWith("/_engyne")) {
return NextResponse.rewrite(
new URL(pathname, `https://${engyneSubdomain}.engyne.page`),
);
}
return NextResponse.next();
}