Something went wrong. Try again.
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364import { Hono } from 'hono';import { serviceManager } from '../services/service-manager';import { VmRegistry } from '../services/vm-registry';
const app = new Hono();const vmRegistry = new VmRegistry(serviceManager);
// GET /vms — List all registered services/VMsapp.get('/', async (c) => { try { const vms = await vmRegistry.list(); return c.json({ vms }); } catch (error: any) { return c.json({ error: 'Failed to list VMs' }, 500); }});
// GET /vms/:id — Get specific VM status + healthapp.get('/:id', async (c) => { try { const vm = await vmRegistry.get(c.req.param('id')); if (!vm) { return c.json({ error: 'VM not found' }, 404); } return c.json(vm); } catch (error: any) { return c.json({ error: 'Failed to get VM' }, 500); }});
// POST /vms/:id/start — Start a stopped serviceapp.post('/:id/start', async (c) => { const service = serviceManager.get(c.req.param('id')); if (!service) { return c.json({ error: 'Service not found' }, 404); }
try { await service.start(); const health = await service.health(); return c.json({ name: service.name, status: health.status }); } catch (error: any) { return c.json({ error: 'Failed to start service' }, 500); }});
// POST /vms/:id/stop — Stop a running serviceapp.post('/:id/stop', async (c) => { const service = serviceManager.get(c.req.param('id')); if (!service) { return c.json({ error: 'Service not found' }, 404); }
try { await service.stop(); const health = await service.health(); return c.json({ name: service.name, status: health.status }); } catch (error: any) { return c.json({ error: 'Failed to stop service' }, 500); }});
export default app;