diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..e330519 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,28 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Next.js: debug server-side", + "type": "node-terminal", + "request": "launch", + "command": "npm run dev" + }, + { + "name": "Next.js: debug client-side", + "type": "chrome", + "request": "launch", + "url": "http://localhost:3000" + }, + { + "name": "Next.js: debug full stack", + "type": "node-terminal", + "request": "launch", + "command": "npm run dev", + "serverReadyAction": { + "pattern": "- Local:.+(https?://.+)", + "uriFormat": "%s", + "action": "debugWithChrome" + } + } + ] + } \ No newline at end of file diff --git a/app/api/caddy/config/route.ts b/app/api/caddy/config/route.ts new file mode 100644 index 0000000..f129e3c --- /dev/null +++ b/app/api/caddy/config/route.ts @@ -0,0 +1,15 @@ +// Import the NextJS API route handler +import { getConfig } from '@/lib/utils'; +import { NextResponse } from 'next/server'; + +// Define the route handler function +export async function GET() { + let caddyConfig = await getConfig(); + + return new NextResponse(JSON.stringify(caddyConfig), { + status: 200, + headers: { + 'Content-Type': 'application/json', + }, + }); +} \ No newline at end of file diff --git a/app/api/caddy/routes/requests/route.ts b/app/api/caddy/routes/requests/route.ts new file mode 100644 index 0000000..90eb217 --- /dev/null +++ b/app/api/caddy/routes/requests/route.ts @@ -0,0 +1,33 @@ +import { getConfig, getRouteUpstreams, getUpstreamRequests } from '@/lib/utils'; +import { NextApiRequest } from 'next'; +import { NextResponse } from 'next/server'; + +export async function POST(req: Request) { + + //TODO, Christ, maybe I'm not a dev + if (!true) { + return new NextResponse(JSON.stringify({"error": "An error has occurred. Please check for a valid body and retry."}), { + status: 400, + headers: { + 'Content-Type': 'appliation/json', + }, + }); + } + + let route: Route = await req.json(); + let upstreams: UpstreamRequest[] = await getUpstreamRequests(route); + let routeUpstreams: Upstream[] = getRouteUpstreams(route); + + let upstreamsRequested: UpstreamRequest[] = upstreams.filter(upstream => { + return routeUpstreams.find(routeUpstream => { + return routeUpstream.dial === upstream.address; + }); + }); + + return new NextResponse(JSON.stringify(upstreamsRequested), { + status: 200, + headers: { + 'Content-Type': 'application/json', + }, + }); +} \ No newline at end of file