fix(note): use relative redirect Location behind proxy
All checks were successful
Deploy eCourt Note Web to Server / Validate Database Schema (Drizzle) (push) Successful in 4s
Deploy eCourt Note Web to Server / Build Web Docker Image (push) Successful in 1m10s
Deploy eCourt Note Web to Server / Deploy eCourt Note Web to Server (push) Successful in 4s
Deploy eCourt Note Web to Server / Notify Deployment Status (push) Successful in 1s
All checks were successful
Deploy eCourt Note Web to Server / Validate Database Schema (Drizzle) (push) Successful in 4s
Deploy eCourt Note Web to Server / Build Web Docker Image (push) Successful in 1m10s
Deploy eCourt Note Web to Server / Deploy eCourt Note Web to Server (push) Successful in 4s
Deploy eCourt Note Web to Server / Notify Deployment Status (push) Successful in 1s
หลัง reverse proxy ที่เขียนทับ Host เป็น upstream (nginx default \$proxy_host เช่น 0.0.0.0:3000) การ 302 ด้วย NextResponse.redirect( new URL(path, request.url)) ประกอบ absolute URL จาก origin ฝั่ง server ทำให้บน prod กดลิงก์เปิดเอกสารตัวอย่างแล้ว browser ถูกพาไป https://0.0.0.0:3000/docedit/note/annotate/... แทนโฮสต์จริง เปลี่ยนเป็น Location แบบ relative (NextResponse + header เอง) ให้ browser resolve เทียบ origin ที่ตัวเองยิงมา — ถูกเสมอไม่ว่า proxy จะตั้ง header แบบไหน: - GET /api/note/files/open: 302 เข้า viewer และ 302 หน้าแรก กรณี fileError - GET /api/note/auth/dev-link: 302 เข้า /note?fileUrl=…&t=… ไม่แตะ dev-link POST ที่คืน {url} เต็ม — dev-only และลิงก์ต้อง absolute เพื่อคัดลอกไปเปิดที่อื่น Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
parent
a288e5643c
commit
83a2cc3e5e
2 changed files with 14 additions and 6 deletions
|
|
@ -16,10 +16,15 @@ export async function GET(request: Request): Promise<Response> {
|
|||
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") ?? "";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue