Added support for Caddy healthchecks

This commit is contained in:
brian 2023-11-15 00:52:24 -05:00
parent a1a23e20b9
commit 1bf9a7d153
3 changed files with 76 additions and 0 deletions

28
.vscode/launch.json vendored Normal file
View file

@ -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"
}
}
]
}

View file

@ -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',
},
});
}

View file

@ -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',
},
});
}