Path: blob/master/webhooks/webhook_preview/app/api/new-webhook/route.ts
640 views
import { prisma } from "@/lib/prisma";1import { NextResponse } from "next/server";2import type { NextRequest } from "next/server";34export async function POST(request: NextRequest) {5try {6const body = await request.json();7const { uuid } = body;89const uuidRegex =10/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;1112if (!uuid || !uuidRegex.test(uuid)) {13return NextResponse.json(14{ success: false, message: "Invalid UUID" },15{ status: 400 },16);17}1819let webhook = await prisma.webhook.findUnique({20where: { uuid },21});2223if (!webhook) {24webhook = await prisma.webhook.create({25data: { uuid },26});27}2829return NextResponse.json(30{ success: true, message: "Webhook created" },31{ status: 201 },32);33} catch (error) {34console.error("Webhook creation error:", error);35return NextResponse.json(36{ success: false, message: "Internal Server Error" },37{ status: 500 },38);39}40}414243