aboutsummaryrefslogtreecommitdiffstats
path: root/middleware/src/app/api/notifications/get/route.ts
blob: 61508225c906b61c847f5c33743fdae74c7fa077 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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/notification/get?topic=<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<string[]>(key);

  return new Response(JSON.stringify({ topic, tokens }), {
    status: 200,
    headers: { "Content-Type": "application/json" },
  });
}
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage