From 78aa1512446072fdec94c86360c9aee3ea932db1 Mon Sep 17 00:00:00 2001 From: Pinapelz Date: Fri, 3 Oct 2025 13:07:33 -0700 Subject: add redis fcm notif topic saving --- middleware/src/app/api/notifications/get/route.ts | 26 +++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 middleware/src/app/api/notifications/get/route.ts (limited to 'middleware/src/app/api/notifications/get') diff --git a/middleware/src/app/api/notifications/get/route.ts b/middleware/src/app/api/notifications/get/route.ts new file mode 100644 index 0000000..344e41b --- /dev/null +++ b/middleware/src/app/api/notifications/get/route.ts @@ -0,0 +1,26 @@ +import { Redis } from "@upstash/redis"; + +export const runtime = "edge"; + +const redis = new Redis({ + url: process.env.KV_REST_API_URL!, + token: process.env.KV_REST_API_TOKEN!, +}); + +// /api/fcm/list?topic= +export async function GET(req: Request) { + const { searchParams } = new URL(req.url); + const topic = searchParams.get("topic"); + + if (!topic) { + return new Response(JSON.stringify({ error: "Missing topic" }), { status: 400 }); + } + + const key = `fcm-${topic}`; + const tokens = await redis.smembers(key); + + return new Response(JSON.stringify({ topic, tokens }), { + status: 200, + headers: { "Content-Type": "application/json" }, + }); +} -- cgit v1.2.3