29 lines
839 B
TypeScript
29 lines
839 B
TypeScript
import { NextRequest, NextResponse } from "next/server";
|
|
import { prisma } from "@/lib/prisma";
|
|
|
|
export async function GET(req: NextRequest) {
|
|
const { searchParams } = new URL(req.url);
|
|
const subdomain = searchParams.get("subdomain");
|
|
|
|
if (!subdomain) {
|
|
return NextResponse.json({ error: "subdomain required" }, { status: 400 });
|
|
}
|
|
|
|
const instance = await prisma.instance.findUnique({
|
|
where: { id: subdomain },
|
|
include: { node: true },
|
|
});
|
|
|
|
if (!instance || !instance.node) {
|
|
return NextResponse.json({ error: "instance not found" }, { status: 404 });
|
|
}
|
|
|
|
if (instance.node.status !== "online" || !instance.node.tailscaleIp) {
|
|
return NextResponse.json({ error: "node offline" }, { status: 503 });
|
|
}
|
|
|
|
return NextResponse.json({
|
|
upstream: `${instance.node.tailscaleIp}:${instance.port}`,
|
|
});
|
|
}
|