Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions apps/logicsrc-web/src/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import type { NextRequest } from "next/server";
// Canonical host: 301 www.* to the bare apex domain over https, preserving
// path + query (e.g. https://www.logicsrc.com/foo -> https://logicsrc.com/foo).
// This is the Next 16 "proxy" (formerly middleware) entrypoint.
const ALLOWED_APEX = process.env.PUBLIC_DOMAIN || "logicsrc.com";

export function proxy(request: NextRequest): NextResponse {
const host = request.headers.get("host") ?? "";
if (host.startsWith("www.")) {
const apexHost = host.slice("www.".length);
if (host === `www.${ALLOWED_APEX}`) {
const { pathname, search } = request.nextUrl;
return NextResponse.redirect(`https://${apexHost}${pathname}${search}`, 301);
return NextResponse.redirect(`https://${ALLOWED_APEX}${pathname}${search}`, 301);
}
return NextResponse.next();
}
Expand Down
Loading