import { NextRequest, NextResponse } from "next/server";
export default async function middleware(req: NextRequest) {
const url = req.nextUrl;
// Get hostname of request (e.g. demo.vercel.pub, demo.localhost:3000)
const hostname = req.headers
.get("host")!
.replace(".localhost:3000", .${process.env.NEXT_PUBLIC_ROOT_DOMAIN});
// Get the pathname of the request (e.g. /, /about, /blog/first-post)
const path = url.pathname;
// Rewrite to /[domain]/[path] dynamic route
return NextResponse.rewrite(new URL(/${hostname}${path}, req.url));
}
import { NextRequest, NextResponse } from "next/server";
export default async function middleware(req: NextRequest) {
const url = req.nextUrl;
// Get hostname of request (e.g. demo.vercel.pub, demo.localhost:3000)
const hostname = req.headers
.get("host")!
.replace(".localhost:3000", .${process.env.NEXT_PUBLIC_ROOT_DOMAIN});
// Get the pathname of the request (e.g. /, /about, /blog/first-post)
const path = url.pathname;
// Rewrite to /[domain]/[path] dynamic route
return NextResponse.rewrite(new URL(/${hostname}${path}, req.url));
}