Routing every domain to the right shop
Each shop has its own domain, but they all hit the same Next.js storefront. A small proxy rewrites every request to an internal path that includes the host, so the page knows which shop it's rendering, and the result is cached separately for each shop.
Browser requests for the cart and checkout go to the shop's own domain and are forwarded to the API with the store attached. Cookies stay first-party on each shop's domain, so no cross-site setup is needed. The admin never guesses the shop from the domain; the store comes from the URL and access needs a membership and permission.
// apps/storefront/src/proxy.ts (simplified)
export function proxy(request: NextRequest) {
const host = request.headers.get("host")!.toLowerCase();
const url = request.nextUrl.clone();
url.pathname = `/s/${host}${url.pathname}`;
return NextResponse.rewrite(url);
}


