Files
homelab-topology/server/config.ts
Christopher Mayor 0910c966a5 feat: migrate from static config to database and add authentication
- Replaced static hosts.json and staticConfig.ts with SQLite database (Prisma)

- Implemented JWT authentication and Login UI

- Added dynamic API routes for hosts, topology, and settings

- Updated UI components to fetch and manage state dynamically

- Added Settings interface for managing hosts and topology nodes
2026-02-25 14:07:11 -08:00

32 lines
801 B
TypeScript

import { homedir } from 'os';
import { PrismaClient } from '@prisma/client';
import { HostConfig } from './types';
const prisma = new PrismaClient();
export async function getHostConfigs(): Promise<HostConfig[]> {
try {
const dbConfigs = await prisma.hostConfig.findMany();
return dbConfigs.map(h => ({
name: h.name,
ip: h.ip,
sshUser: h.sshUser || 'bear',
sshKeyPath: h.sshKeyPath?.replace(/^~/, homedir()),
sshPort: h.sshPort || 22,
hostType: h.hostType,
}));
} catch (error) {
console.error('Error fetching host configs from DB:', error);
return [];
}
}
export async function hasConfig(): Promise<boolean> {
try {
const count = await prisma.hostConfig.count();
return count > 0;
} catch (error) {
return false;
}
}