Files
Domain_web/src/app/api/monitors/route.ts
Андрей Бобырев 83168af005 feat: rebrand to Domain Scanner platform
Replace GeoExport static site with Next.js domain intelligence app:
real DNS/WHOIS/SSL/HTTP/geo scans, SSE progress, Docker stack,
updated install/uninstall scripts, and full documentation.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-24 21:48:32 +03:00

52 lines
1.4 KiB
TypeScript

import { NextRequest, NextResponse } from "next/server";
import { z } from "zod";
import { auth } from "@/lib/auth";
import { prisma } from "@/lib/prisma";
import { normalizeDomain, isValidDomain } from "@/lib/utils";
const bodySchema = z.object({
domain: z.string(),
type: z.enum(["DNS", "SSL", "UPTIME"]),
});
export async function GET() {
const session = await auth();
if (!session?.user?.id) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}
const monitors = await prisma.monitor.findMany({
where: { userId: session.user.id },
orderBy: { createdAt: "desc" },
});
return NextResponse.json({ monitors });
}
export async function POST(req: NextRequest) {
const session = await auth();
if (!session?.user?.id) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}
let body: z.infer<typeof bodySchema>;
try {
body = bodySchema.parse(await req.json());
} catch {
return NextResponse.json({ error: "Invalid body" }, { status: 400 });
}
const domain = normalizeDomain(body.domain);
if (!isValidDomain(domain)) {
return NextResponse.json({ error: "Invalid domain" }, { status: 400 });
}
const monitor = await prisma.monitor.create({
data: {
domain,
type: body.type,
userId: session.user.id,
},
});
return NextResponse.json({ monitor }, { status: 201 });
}