File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -4,12 +4,13 @@ import type { NextRequest } from "next/server";
44// Canonical host: 301 www.* to the bare apex domain over https, preserving
55// path + query (e.g. https://www.logicsrc.com/foo -> https://logicsrc.com/foo).
66// This is the Next 16 "proxy" (formerly middleware) entrypoint.
7+ const ALLOWED_APEX = process . env . PUBLIC_DOMAIN || "logicsrc.com" ;
8+
79export function proxy ( request : NextRequest ) : NextResponse {
810 const host = request . headers . get ( "host" ) ?? "" ;
9- if ( host . startsWith ( "www." ) ) {
10- const apexHost = host . slice ( "www." . length ) ;
11+ if ( host === `www.${ ALLOWED_APEX } ` ) {
1112 const { pathname, search } = request . nextUrl ;
12- return NextResponse . redirect ( `https://${ apexHost } ${ pathname } ${ search } ` , 301 ) ;
13+ return NextResponse . redirect ( `https://${ ALLOWED_APEX } ${ pathname } ${ search } ` , 301 ) ;
1314 }
1415 return NextResponse . next ( ) ;
1516}
You can’t perform that action at this time.
0 commit comments