import { NextRequest , NextResponse } from 'next/server' ; export default function middleware ( req ) { const { pathname } = req . nextUrl ; const hostname = req . headers . get ( 'host' ) ; const currentHost = process . env . NODE_ENV == 'production' ? hostname . replace ( `.${ process . env . ROOT_URL }` , '' ) : process . env . CURR_HOST ; if ( pathname . startsWith ( `/_sites` ) ) { return new Response ( null , { status : 404 } ) ; } if ( ! pathname . includes ( '.' ) && ! pathname . startsWith ( '/api' ) ) { return NextResponse . rewrite ( `/_sites/${ currentHost }${ pathname }` ) ; } }