From 1f08997684bc4a187a8a0f020fb8076eac37aaa1 Mon Sep 17 00:00:00 2001 From: IqbalRizqiR Date: Wed, 30 Apr 2025 10:11:27 +0700 Subject: [PATCH 1/2] #389 bug : fix error page not showing properly --- src/app/(twibbon)/twbn/[slug]/page.tsx | 27 ++++++++++++++++++++++++++ src/app/(twibbon)/twbn/[slug]/route.ts | 23 ---------------------- 2 files changed, 27 insertions(+), 23 deletions(-) create mode 100644 src/app/(twibbon)/twbn/[slug]/page.tsx delete mode 100644 src/app/(twibbon)/twbn/[slug]/route.ts diff --git a/src/app/(twibbon)/twbn/[slug]/page.tsx b/src/app/(twibbon)/twbn/[slug]/page.tsx new file mode 100644 index 00000000..1b6e1729 --- /dev/null +++ b/src/app/(twibbon)/twbn/[slug]/page.tsx @@ -0,0 +1,27 @@ +import { notFound, redirect } from "next/navigation"; +import { findTwibbon } from "@/utils/database/twibbon.query"; + +export default async function TwibbonRedirectPage({ + params, +}: { + params: { slug: string }; +}) { + const { slug } = params; + const twibbon = await findTwibbon({ slug }); + + if (!twibbon) { + return notFound(); + } + + redirect( + `https://twibbon.moklet.org/go?` + + new URLSearchParams({ + title: twibbon.title, + slug, + frameUrl: twibbon.frame_url, + ...(twibbon.caption + ? { caption: encodeURIComponent(twibbon.caption) } + : {}), + }).toString() + ); +} \ No newline at end of file diff --git a/src/app/(twibbon)/twbn/[slug]/route.ts b/src/app/(twibbon)/twbn/[slug]/route.ts deleted file mode 100644 index 860c3782..00000000 --- a/src/app/(twibbon)/twbn/[slug]/route.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { internalServerError } from "@/utils/apiResponse"; -import { findTwibbon } from "@/utils/database/twibbon.query"; -import { notFound } from "next/navigation"; -import { NextRequest, NextResponse } from "next/server"; - -export async function GET( - req: NextRequest, - { params }: { params: { slug: string } }, -) { - try { - const { slug } = params; - const twibbon = await findTwibbon({ slug }); - - if (!twibbon) return notFound(); - - return NextResponse.redirect( - `https://twibbon.moklet.org/go?title=${twibbon.title}&slug=${slug}&frameUrl=${twibbon.frame_url}${twibbon?.caption ? "&caption=" + encodeURIComponent(twibbon.caption as string) : ""}`, - { status: 302 }, - ); - } catch (error) { - return internalServerError([]); - } -} From 2214da5f8fa360c0472b58e026346b9888bb5f6e Mon Sep 17 00:00:00 2001 From: IqbalRizqiR Date: Wed, 30 Apr 2025 10:12:36 +0700 Subject: [PATCH 2/2] bug #389: fixing bug 404 error page not show properly --- src/app/(twibbon)/twbn/[slug]/page.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/(twibbon)/twbn/[slug]/page.tsx b/src/app/(twibbon)/twbn/[slug]/page.tsx index 1b6e1729..761fae8f 100644 --- a/src/app/(twibbon)/twbn/[slug]/page.tsx +++ b/src/app/(twibbon)/twbn/[slug]/page.tsx @@ -22,6 +22,6 @@ export default async function TwibbonRedirectPage({ ...(twibbon.caption ? { caption: encodeURIComponent(twibbon.caption) } : {}), - }).toString() + }).toString(), ); -} \ No newline at end of file +}