import { NextResponse, type NextRequest } from "next/server"; /** * A shared preview link (ยง4): keeps its token in a cookie for the rest of the visit, so every page * shows the working copy. The backend checks the token (7 days, until revoked) on every page. */ export async function GET(request: NextRequest, { params }: { params: Promise<{ token: string }> }) { const { token } = await params; const res = NextResponse.redirect(new URL("/", request.url), 303); if (/^[A-Za-z0-9_-]{20,100}$/.test(token)) { res.cookies.set("ccw_preview", token, { httpOnly: true, sameSite: "lax", secure: process.env.NODE_ENV === "production", path: "/", maxAge: 7 * 86400 }); } res.headers.set("X-Robots-Tag", "noindex, nofollow"); return res; }