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: {