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 body = req.body || {};
|
||||
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 {
|
||||
const { serverId, type = 'all', dryRun = true } = body;
|
||||
if (!serverId) {
|
||||
@@ -344,7 +352,7 @@ async function applyMikrotikConfig(req, res) {
|
||||
msg.includes('Authentication') || msg.includes('login') ? 'Неверный логин или пароль' : msg,
|
||||
};
|
||||
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-recursive-routes', mikrotikConfigRoutes.generateRecursiveRoutes);
|
||||
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);
|
||||
|
||||
// === MIKROTIK VALIDATION ===
|
||||
|
||||
Reference in New Issue
Block a user