fix(caddy): prevent duplicate routes and make status/routes fetches independent
POST /api/caddy/routes now returns 409 if the hostname already exists, preventing duplicate DB entries that cause Caddy's "ambiguous site definition" error. loadCaddyRoutes uses Promise.allSettled so a failure in the status check can no longer silently prevent the routes list from loading.
This commit is contained in:
@ -1192,6 +1192,8 @@ async function startServer() {
|
||||
hostname?: string; upstream?: string; tls?: boolean; compress?: boolean;
|
||||
};
|
||||
if (!hostname || !upstream) return res.status(400).json({ error: 'hostname and upstream are required.' });
|
||||
if (getCaddyRoutes().some(r => r.hostname === hostname.trim()))
|
||||
return res.status(409).json({ error: `Route for ${hostname.trim()} already exists.` });
|
||||
const route = addCaddyRoute(hostname.trim(), upstream.trim(), tls !== false, compress !== false);
|
||||
db.prepare('INSERT INTO logs (id, timestamp, type, message, deviceId, userId) VALUES (?, ?, ?, ?, ?, ?)')
|
||||
.run(uid('log'), new Date().toISOString(), 'system',
|
||||
|
||||
Reference in New Issue
Block a user