mirror of
https://github.com/andrey271192/Domain_web.git
synced 2026-09-20 14:41:58 +00:00
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>
52 lines
1.4 KiB
TypeScript
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 });
|
|
}
|