Some checks failed
Build and Push Docker Images (Trusted) / build-and-push (., docker/caddy/Dockerfile, caddy) (push) Has been cancelled
Build and Push Docker Images (Trusted) / build-and-push (., docker/l4-port-manager/Dockerfile, l4-port-manager) (push) Has been cancelled
Build and Push Docker Images (Trusted) / build-and-push (., docker/web/Dockerfile, web) (push) Has been cancelled
Tests / test (push) Has been cancelled
50 lines
1.4 KiB
TypeScript
Executable File
50 lines
1.4 KiB
TypeScript
Executable File
import { NextRequest, NextResponse } from "next/server";
|
|
import { requireApiAdmin, apiErrorResponse } from "@/src/lib/api-auth";
|
|
import { getL4ProxyHost, updateL4ProxyHost, deleteL4ProxyHost } from "@/src/lib/models/l4-proxy-hosts";
|
|
|
|
export async function GET(
|
|
request: NextRequest,
|
|
{ params }: { params: Promise<{ id: string }> }
|
|
) {
|
|
try {
|
|
await requireApiAdmin(request);
|
|
const { id } = await params;
|
|
const host = await getL4ProxyHost(Number(id));
|
|
if (!host) {
|
|
return NextResponse.json({ error: "Not found" }, { status: 404 });
|
|
}
|
|
return NextResponse.json(host);
|
|
} catch (error) {
|
|
return apiErrorResponse(error);
|
|
}
|
|
}
|
|
|
|
export async function PUT(
|
|
request: NextRequest,
|
|
{ params }: { params: Promise<{ id: string }> }
|
|
) {
|
|
try {
|
|
const { userId } = await requireApiAdmin(request);
|
|
const { id } = await params;
|
|
const body = await request.json();
|
|
const host = await updateL4ProxyHost(Number(id), body, userId);
|
|
return NextResponse.json(host);
|
|
} catch (error) {
|
|
return apiErrorResponse(error);
|
|
}
|
|
}
|
|
|
|
export async function DELETE(
|
|
request: NextRequest,
|
|
{ params }: { params: Promise<{ id: string }> }
|
|
) {
|
|
try {
|
|
const { userId } = await requireApiAdmin(request);
|
|
const { id } = await params;
|
|
await deleteL4ProxyHost(Number(id), userId);
|
|
return NextResponse.json({ ok: true });
|
|
} catch (error) {
|
|
return apiErrorResponse(error);
|
|
}
|
|
}
|