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
This commit is contained in:
50
server/routes/hosts.ts
Normal file
50
server/routes/hosts.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import { Router } from 'express';
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
|
||||
const router = Router();
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
// GET all host configurations
|
||||
router.get('/hosts', async (req, res) => {
|
||||
try {
|
||||
const hosts = await prisma.hostConfig.findMany();
|
||||
res.json({ status: 'success', hosts });
|
||||
} catch (error) {
|
||||
res.status(500).json({ status: 'error', message: 'Failed to fetch host configs' });
|
||||
}
|
||||
});
|
||||
|
||||
// POST a new host configuration
|
||||
router.post('/hosts', async (req, res) => {
|
||||
try {
|
||||
const host = await prisma.hostConfig.create({ data: req.body });
|
||||
res.json({ status: 'success', host });
|
||||
} catch (error) {
|
||||
res.status(400).json({ status: 'error', message: 'Failed to create host config. Ensure name is unique.' });
|
||||
}
|
||||
});
|
||||
|
||||
// PUT (update) a host configuration
|
||||
router.put('/hosts/:id', async (req, res) => {
|
||||
try {
|
||||
const host = await prisma.hostConfig.update({
|
||||
where: { id: req.params.id },
|
||||
data: req.body,
|
||||
});
|
||||
res.json({ status: 'success', host });
|
||||
} catch (error) {
|
||||
res.status(400).json({ status: 'error', message: 'Failed to update host config' });
|
||||
}
|
||||
});
|
||||
|
||||
// DELETE a host configuration
|
||||
router.delete('/hosts/:id', async (req, res) => {
|
||||
try {
|
||||
await prisma.hostConfig.delete({ where: { id: req.params.id } });
|
||||
res.json({ status: 'success' });
|
||||
} catch (error) {
|
||||
res.status(400).json({ status: 'error', message: 'Failed to delete host config' });
|
||||
}
|
||||
});
|
||||
|
||||
export default router;
|
||||
Reference in New Issue
Block a user