32 lines
949 B
TypeScript
32 lines
949 B
TypeScript
import type { IncomingMessage, ServerResponse } from 'http';
|
|
import type { HostApiContext } from '../context';
|
|
import { sendJson } from '../route-utils';
|
|
|
|
export async function handleHermesRoutes(
|
|
req: IncomingMessage,
|
|
res: ServerResponse,
|
|
url: URL,
|
|
ctx: HostApiContext,
|
|
): Promise<boolean> {
|
|
if (url.pathname === '/api/hermes/status' && req.method === 'GET') {
|
|
const status = await ctx.hermesManager.refreshStatus();
|
|
sendJson(res, 200, { success: true, status });
|
|
return true;
|
|
}
|
|
|
|
if (url.pathname === '/api/hermes/install' && req.method === 'POST') {
|
|
const result = await ctx.hermesManager.install();
|
|
sendJson(res, result.success ? 200 : 500, { ...result });
|
|
return true;
|
|
}
|
|
|
|
if (url.pathname === '/api/hermes/start' && req.method === 'POST') {
|
|
const result = await ctx.hermesManager.startGateway();
|
|
sendJson(res, result.success ? 200 : 500, { ...result });
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|