eCourt-note/app/page.tsx

34 lines
1.6 KiB
TypeScript
Raw Normal View History

import { redirect } from "next/navigation";
// หน้า root (/docedit) — แทน redirects() เดิมใน next.config.mjs (ถอดออกลด hop
2026-10-16 12:07:25 +07:00
// ที่ Next สั่งเองตอน deploy หลัง IIS/proxy)
// ตามคำขอผู้ใช้ 2026-10-14: เปิด /docedit เปล่า ๆ → เข้า taskpane ของ wordaddin
// เลย (/wordaddin — middleware ไม่บังคับ login ที่ root) ยกเว้น**ลิงก์ e-Court**
// /docedit/?fileUrl=&fileId=&typeId= (N8) ที่ยังส่งต่อให้ /note เหมือนเดิม —
// redirect() ไม่แนบ searchParams ให้อัตโนมัติเหมือน redirects() จึงต้องส่งต่อเอง
// (redirect ของ next/navigation เติม basePath ให้เอง — invariant #12)
2026-10-16 12:07:25 +07:00
const ECOURT_PARAM_KEYS = ["fileUrl", "fileId", "typeId"] as const;
export default function RootPage({
searchParams,
}: {
searchParams: Record<string, string | string[] | undefined>;
}) {
2026-10-16 12:07:25 +07:00
const entries = Object.entries(searchParams);
const isEcourtLink = entries.some(([key]) =>
(ECOURT_PARAM_KEYS as readonly string[]).includes(key),
);
if (!isEcourtLink) {
redirect("/wordaddin");
}
const qs = new URLSearchParams();
2026-10-16 12:07:25 +07:00
for (const [key, value] of entries) {
if (typeof value === "string") {
qs.set(key, value);
} else if (Array.isArray(value)) {
for (const v of value) qs.append(key, v);
}
}
2026-10-16 12:07:25 +07:00
redirect(`/note?${qs.toString()}`);
}