From 7a146d48be2010aab70e8d7f38c51e65539aede9 Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 8 Oct 2026 11:11:48 +0700 Subject: [PATCH] fix(config): move root redirect to page and skip slash redirect MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - เข้า /docedit เดิมใช้ redirects() (Next เติม basePath ให้ source /) ถอดออกให้ app/page.tsx ที่ root จับ /docedit และ /docedit/ แทน พร้อมส่งต่อ query เอง เพราะ redirect() ของ next/navigation ไม่แนบ searchParams ให้อัตโนมัติ (รักษาสัญญาลิงก์ e-Court /docedit/?fileUrl=&fileId=&typeId= ของ N8) - เพิ่ม skipTrailingSlashRedirect: true ปิด 308 trailing slash อัตโนมัติของ Next กัน ping-pong กับ rewrite rule ของ IIS ตอน deploy หลัง proxy - redirects() ใหม่แบบ basePath:false จับเฉพาะ root ของ host (/ แท้) ส่งตรงไป /docedit/note Co-Authored-By: Claude Code --- app/page.tsx | 23 +++++++++++++++++++++++ next.config.mjs | 20 +++++++++++++++++--- 2 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 app/page.tsx diff --git a/app/page.tsx b/app/page.tsx new file mode 100644 index 0000000..cd22e59 --- /dev/null +++ b/app/page.tsx @@ -0,0 +1,23 @@ +import { redirect } from "next/navigation"; + +// หน้า root (/docedit) — แทน redirects() เดิมใน next.config.mjs (ถอดออกลด hop +// ที่ Next สั่งเองตอน deploy หลัง IIS/proxy): พาเข้าหน้ารายการของ /note เสมอ +// — redirect() ไม่แนบ searchParams ให้อัตโนมัติเหมือน redirects() จึงต้องส่งต่อ +// เอง ไม่งั้นสัญญาลิงก์ e-Court /docedit/?fileUrl=&fileId=&typeId= (N8) พัง +// (redirect ของ next/navigation เติม basePath ให้เอง — invariant #12) +export default function RootPage({ + searchParams, +}: { + searchParams: Record; +}) { + const qs = new URLSearchParams(); + for (const [key, value] of Object.entries(searchParams)) { + if (typeof value === "string") { + qs.set(key, value); + } else if (Array.isArray(value)) { + for (const v of value) qs.append(key, v); + } + } + const query = qs.toString(); + redirect(`/note${query ? `?${query}` : ""}`); +} diff --git a/next.config.mjs b/next.config.mjs index 88d1806..3f579e0 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -14,10 +14,24 @@ const nextConfig = { basePath, // expose ให้โค้ดใช้ (inline ตอน build) — ค่าจริงประกาศที่เดียวที่ไฟล์นี้ env: { NEXT_PUBLIC_BASE_PATH: basePath, NEXT_PUBLIC_APP_PATH: appPath }, - // เข้า /docedit/ ตรง ๆ (ไม่มี route ที่ root) → โผล่ที่หน้ารายการของ /note - // (Next เติม basePath ให้ source/destination เอง + query ส่งต่ออัตโนมัติ — รองรับ /docedit/?fileUrl=…) + // ปิด redirect trailing slash อัตโนมัติของ Next (308 /docedit → /docedit/ + // และ /docedit/note/ → /docedit/note) — deploy หลัง IIS แล้ว redirect พวกนี้ + // ตีกับ rewrite rule ของ IIS จนกลายเป็น ping-pong loop; ปิดให้หน้า/ไฟล์ทุกอย่าง + // serve ได้ทั้งแบบมี/ไม่มี slash ฝั่ง proxy เป็นคนกำหนดเอง + skipTrailingSlashRedirect: true, + // จับเฉพาะ root ของ host ("/" แท้ ๆ — basePath:false ทำให้ rule นี้ไม่จับ + // /docedit) เผื่อ IIS ส่ง path "/" เข้า process: ส่งตรงไป /docedit/note เลย + // ส่วน /docedit และ /docedit/ จับที่ app/page.tsx แทน (ส่งต่อ query เอง — + // รักษาสัญญาลิงก์ e-Court /docedit/?fileUrl=&fileId=&typeId=) async redirects() { - return [{ source: "/", destination: appPath, permanent: false }]; + return [ + { + source: "/", + destination: `${basePath}${appPath}`, + basePath: false, // ป้องกัน basePath ซ้อน (destination เขียนเต็มแล้ว) + permanent: false, + }, + ]; }, // N4 อัปโหลดไฟล์ผ่าน Server Action — default 1MB ไม่พอสำหรับ PDF/สแกนศาล (ต้องตรงกับ MAX_UPLOAD_BYTES ใน app/actions/files.ts) experimental: {