Last active
February 23, 2024 15:49
-
-
Save bdcorps/3acb8e4aea5f4b0f0d50d4af3758108f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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