diff --git a/app/api/note/auth/dev-link/route.ts b/app/api/note/auth/dev-link/route.ts index ae21397..e8fa16a 100644 --- a/app/api/note/auth/dev-link/route.ts +++ b/app/api/note/auth/dev-link/route.ts @@ -62,9 +62,12 @@ export async function GET(request: Request): Promise { // ปลายทาง = หน้าแรก /note พร้อม credential + fileUrl เหมือนลิงก์จริง — ให้ bootstrap // ของ NoteHome แลกเป็น session token แล้วพาเข้า viewer (เห็น URL ทุกขั้นตอน) - const res = NextResponse.redirect(new URL(`${withBasePath("")}?${params.toString()}`, url), 302); - res.headers.set("cache-control", "no-store"); - return res; + // Location relative เหมือน files/open — origin ของ request หลัง reverse proxy + // (Host ถูกเขียนทับเป็น upstream) ไม่น่าเชื่อพอจะประกอบ absolute URL + return new NextResponse(null, { + status: 302, + headers: { location: `${withBasePath("")}?${params.toString()}`, "cache-control": "no-store" }, + }); } export async function POST(request: Request): Promise { diff --git a/app/api/note/files/open/route.ts b/app/api/note/files/open/route.ts index 3b555f3..263329d 100644 --- a/app/api/note/files/open/route.ts +++ b/app/api/note/files/open/route.ts @@ -16,10 +16,15 @@ export async function GET(request: Request): Promise { const url = new URL(request.url); // withBasePath("") = หน้าแรก /docedit/note · withBasePath("/annotate/x") = viewer — // อย่าส่ง "/note" เข้า withBasePath (มันเติม app path ให้อีกชั้นเป็น /note/note — D11) + // Location เป็น relative โดยเจตนา: browser resolve เทียบ origin ที่ตัวเองยิงมาเอง + // ส่วน NextResponse.redirect(new URL(path, request.url)) จะประกอบ absolute URL จาก + // Host ที่ reverse proxy ส่งมา (nginx default เขียนทับเป็น upstream เช่น 0.0.0.0:3000) + // แล้วพา browser หลุดโฮสต์จริง (prod 2026-11-02) const redirectTo = (path: string, query = ""): NextResponse => { - const res = NextResponse.redirect(new URL(`${withBasePath(path)}${query}`, url), 302); - res.headers.set("cache-control", "no-store"); - return res; + return new NextResponse(null, { + status: 302, + headers: { location: `${withBasePath(path)}${query}`, "cache-control": "no-store" }, + }); }; const fileUrl = url.searchParams.get("fileUrl") ?? "";