fix(domain-proxy): improve endpoint and logic to retrieve domain proxy capabilities

This commit is contained in:
KodekaTeam committed 2026-08-07 14:52:54 +07:00
1 parent e71eaaa6ef
commit e488207bf8
6 files changed
+122 -37

No files matched your search

+22
View File
@@ -715,6 +715,28 @@ export async function serverRoutes(app: FastifyInstance) {
},
);
app.get(
"/:id/domain-proxy-capability",
{ preHandler: serverReadAccess },
async (req, reply) => {
const { id } = req.params as { id: string };
const server = await getAccessibleServer(req.userId, id, req.organizationId);
if (!server) {
return reply.status(403).send({ success: false, error: "Forbidden" });
}
try {
const data = await ssh.getDomainProxyCapability(server);
return reply.send({ success: true, data });
} catch (err: unknown) {
return reply.status(500).send({
success: false,
error: err instanceof Error ? err.message : "Failed to inspect domain proxy capability",
});
}
},
);
app.get(
"/:id/config",
{ preHandler: serverReadAccess },
@@ -118,6 +118,33 @@ export interface ServerConfigSnapshot {
fetchedAt: string;
}
export interface DomainProxyCapability {
nginx: boolean;
caddy: boolean;
certbot: boolean;
}
/** A focused probe for the domain form; avoids loading the full server snapshot. */
export async function getDomainProxyCapability(
server: Server,
): Promise<DomainProxyCapability> {
const result = await exec(
server,
`bash -lc ${escapeShellArg([
'has_command() { command -v "$1" >/dev/null 2>&1 && return 0; shift; for candidate in "$@"; do [ -x "$candidate" ] && return 0; done; return 1; }',
'is_active() { systemctl is-active --quiet "$1" 2>/dev/null; }',
'nginx=0; if has_command nginx /usr/sbin/nginx /usr/bin/nginx /usr/local/sbin/nginx /usr/local/bin/nginx /usr/local/nginx/sbin/nginx && is_active nginx; then nginx=1; fi',
'caddy=0; if has_command caddy /usr/bin/caddy /usr/sbin/caddy /usr/local/bin/caddy /usr/local/sbin/caddy && is_active caddy; then caddy=1; fi',
'certbot=0; if has_command certbot /snap/bin/certbot /usr/bin/certbot /usr/local/bin/certbot /root/.local/bin/certbot; then certbot=1; fi',
'printf "%s|%s|%s\\n" "$nginx" "$caddy" "$certbot"',
].join("\n"))}`,
configCommandTimeout(CONFIG_FAST_TIMEOUT_MS),
);
const [nginx, caddy, certbot] = result.stdout.trim().split("|");
return { nginx: nginx === "1", caddy: caddy === "1", certbot: certbot === "1" };
}
export async function getServerConfigSnapshot(
server: Server,
): Promise<ServerConfigSnapshot> {