Skip to content

Instantly share code, notes, and snippets.

@bdcorps
Last active February 23, 2024 15:49
Show Gist options
  • Save bdcorps/3acb8e4aea5f4b0f0d50d4af3758108f to your computer and use it in GitHub Desktop.
Save bdcorps/3acb8e4aea5f4b0f0d50d4af3758108f to your computer and use it in GitHub Desktop.
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";
export const config = {
matcher: [
"/((?!_next|fonts|examples|api|[\\w-]+\\.\\w+).*)",
],
};
export default async function middleware(req: NextRequest) {
const engyneSubdomain = "mystartup-indigo" // 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();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment