feat(MikrotikConfig): add ping endpoint and enhance applyMikrotikConfig error handling with safe response method
Publish Fast Tabler Docker image / build-and-push-fast (push) Successful in 1m57s
Publish Fast Tabler Docker image / build-and-push-fast (push) Successful in 1m57s
This commit is contained in:
@@ -241,6 +241,14 @@ async function applyMikrotikConfig(req, res) {
|
|||||||
const mikrotikRequests = [];
|
const mikrotikRequests = [];
|
||||||
const body = req.body || {};
|
const body = req.body || {};
|
||||||
console.log('[MikroTik apply] Request body:', { serverId: body.serverId, type: body.type, dryRun: body.dryRun });
|
console.log('[MikroTik apply] Request body:', { serverId: body.serverId, type: body.type, dryRun: body.dryRun });
|
||||||
|
const sendSafe = (status, data) => {
|
||||||
|
if (res.headersSent) return;
|
||||||
|
try {
|
||||||
|
res.status(status).json(data);
|
||||||
|
} catch (e) {
|
||||||
|
console.error('[MikroTik apply] sendSafe failed:', e);
|
||||||
|
}
|
||||||
|
};
|
||||||
try {
|
try {
|
||||||
const { serverId, type = 'all', dryRun = true } = body;
|
const { serverId, type = 'all', dryRun = true } = body;
|
||||||
if (!serverId) {
|
if (!serverId) {
|
||||||
@@ -344,7 +352,7 @@ async function applyMikrotikConfig(req, res) {
|
|||||||
msg.includes('Authentication') || msg.includes('login') ? 'Неверный логин или пароль' : msg,
|
msg.includes('Authentication') || msg.includes('login') ? 'Неверный логин или пароль' : msg,
|
||||||
};
|
};
|
||||||
if (mikrotikRequests.length > 0) errPayload.mikrotikRequests = mikrotikRequests;
|
if (mikrotikRequests.length > 0) errPayload.mikrotikRequests = mikrotikRequests;
|
||||||
return res.status(500).json(errPayload);
|
sendSafe(500, errPayload);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -450,6 +450,7 @@ app.post('/api/mikrotik/generate', mikrotikConfigRoutes.generateMikrotikConfig);
|
|||||||
app.get('/api/mikrotik/generate-interfaces', mikrotikConfigRoutes.generateInterfaces);
|
app.get('/api/mikrotik/generate-interfaces', mikrotikConfigRoutes.generateInterfaces);
|
||||||
app.get('/api/mikrotik/generate-recursive-routes', mikrotikConfigRoutes.generateRecursiveRoutes);
|
app.get('/api/mikrotik/generate-recursive-routes', mikrotikConfigRoutes.generateRecursiveRoutes);
|
||||||
app.post('/api/mikrotik/test-connection', mikrotikConfigRoutes.testMikrotikConnection);
|
app.post('/api/mikrotik/test-connection', mikrotikConfigRoutes.testMikrotikConnection);
|
||||||
|
app.get('/api/mikrotik/ping', (req, res) => res.json({ ok: true, ts: Date.now() }));
|
||||||
app.post('/api/mikrotik/apply', mikrotikConfigRoutes.applyMikrotikConfig);
|
app.post('/api/mikrotik/apply', mikrotikConfigRoutes.applyMikrotikConfig);
|
||||||
|
|
||||||
// === MIKROTIK VALIDATION ===
|
// === MIKROTIK VALIDATION ===
|
||||||
|
|||||||
@@ -2279,11 +2279,18 @@ function NetworkConfigManager() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const openApplyModal = (serverId) => {
|
const openApplyModal = async (serverId) => {
|
||||||
setApplyServerId(serverId);
|
setApplyServerId(serverId);
|
||||||
setApplyResult(null);
|
setApplyResult(null);
|
||||||
setApplyDryRun(true);
|
setApplyDryRun(true);
|
||||||
setApplyModalOpen(true);
|
setApplyModalOpen(true);
|
||||||
|
try {
|
||||||
|
const r = await fetch('/api/mikrotik/ping');
|
||||||
|
const d = await r.json().catch(() => ({}));
|
||||||
|
console.log('[MikroTik apply] Backend ping:', r.ok ? 'OK' : 'FAIL', d);
|
||||||
|
} catch (e) {
|
||||||
|
console.warn('[MikroTik apply] Backend ping failed:', e.message);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// === Генерация кода MikroTik только для одного интерфейса ===
|
// === Генерация кода MikroTik только для одного интерфейса ===
|
||||||
|
|||||||
Reference in New Issue
Block a user