From e2893932354d35ffc7bf90447a718b2b32d6adc4 Mon Sep 17 00:00:00 2001 From: nicolasburtey Date: Mon, 21 Aug 2023 19:30:52 +0100 Subject: [PATCH] chore: moving manifest to new app router (#534) Co-authored-by: Nicolas Burtey --- .../[username]/manifest/route.ts | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) rename pages/api/[username]/manifest.ts => app/[username]/manifest/route.ts (76%) diff --git a/pages/api/[username]/manifest.ts b/app/[username]/manifest/route.ts similarity index 76% rename from pages/api/[username]/manifest.ts rename to app/[username]/manifest/route.ts index de71cbd2..1cc33001 100644 --- a/pages/api/[username]/manifest.ts +++ b/app/[username]/manifest/route.ts @@ -1,14 +1,18 @@ -import { NextApiRequest, NextApiResponse } from "next" +import { NextResponse } from "next/server" -export default async function (req: NextApiRequest, res: NextApiResponse) { - const { - query: { username, memo }, - } = req +export async function GET( + request: Request, + { params }: { params: { username: string } }, +) { + const username = params.username - const params = new URLSearchParams() + const { searchParams } = new URL(request.url) + const memo = searchParams.get("memo") + + let startUrl = `/${username}` if (memo) { - params.set("memo", memo.toString()) + startUrl = `${startUrl}?memo=${memo}` } const manifest = { @@ -16,7 +20,7 @@ export default async function (req: NextApiRequest, res: NextApiResponse) { short_name: `${username} Register`, description: "A Bitcoin POS cash register application that connects with the merchant's wallet", - start_url: `/${username}?${params.toString()}`, + start_url: startUrl, scope: "/", display: "standalone", background_color: "#536FF2", @@ -66,5 +70,5 @@ export default async function (req: NextApiRequest, res: NextApiResponse) { ], } - res.status(200).send(JSON.stringify(manifest)) + NextResponse.json(manifest) }