@raevon/n8n-nodes-whatsapp 2.0.10 → 2.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -345,20 +345,34 @@ async function startServer(cfg) {
|
|
|
345
345
|
}
|
|
346
346
|
async function ensureServerRunning(cfg) {
|
|
347
347
|
const port = getPort(cfg);
|
|
348
|
-
//
|
|
348
|
+
// Check if server is already running and healthy
|
|
349
349
|
try {
|
|
350
|
-
const res = await fetch(`http://127.0.0.1:${port}/health`, { signal: AbortSignal.timeout(
|
|
350
|
+
const res = await fetch(`http://127.0.0.1:${port}/health`, { signal: AbortSignal.timeout(3000) });
|
|
351
351
|
if (res.ok)
|
|
352
352
|
return; // Server alive
|
|
353
353
|
}
|
|
354
354
|
catch { }
|
|
355
|
-
//
|
|
355
|
+
// Port is in use but server not responding — stale from another worker, can't kill it
|
|
356
|
+
// Just try to use it anyway (might have recovered)
|
|
357
|
+
try {
|
|
358
|
+
const res = await fetch(`http://127.0.0.1:${port}/health`, { signal: AbortSignal.timeout(5000) });
|
|
359
|
+
if (res.ok)
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
catch { }
|
|
363
|
+
// Port truly free — start server
|
|
356
364
|
if (await isPortOpen(port)) {
|
|
357
365
|
await startServer(cfg);
|
|
358
366
|
return;
|
|
359
367
|
}
|
|
360
|
-
// Port occupied
|
|
361
|
-
|
|
368
|
+
// Port occupied, can't start — try to use existing anyway
|
|
369
|
+
try {
|
|
370
|
+
const res = await fetch(`http://127.0.0.1:${port}/connect`, { method: 'POST', signal: AbortSignal.timeout(60000) });
|
|
371
|
+
if (res.ok)
|
|
372
|
+
return; // It worked
|
|
373
|
+
}
|
|
374
|
+
catch { }
|
|
375
|
+
throw new Error(`Port ${port} occupied. Restart n8n container, then try again.`);
|
|
362
376
|
}
|
|
363
377
|
async function stopServer(cfg) {
|
|
364
378
|
const port = getPort(cfg);
|
|
@@ -61,11 +61,20 @@ class WhatsAppConnect {
|
|
|
61
61
|
});
|
|
62
62
|
}
|
|
63
63
|
else if (operation === 'stopServer') {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
64
|
+
// Try graceful shutdown via /signout
|
|
65
|
+
try {
|
|
66
|
+
await fetch(`${(0, WhatsAppApiHelper_1.getServerUrl)(cfg)}/signout`, { method: 'POST', signal: AbortSignal.timeout(3000) });
|
|
67
|
+
returnData.push({
|
|
68
|
+
json: { success: true, message: 'Server stopped', sessionPath: cfg.sessionPath },
|
|
69
|
+
pairedItem: { item: i },
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
returnData.push({
|
|
74
|
+
json: { success: false, message: 'Server may be in another worker. Restart n8n container to fully stop.', sessionPath: cfg.sessionPath },
|
|
75
|
+
pairedItem: { item: i },
|
|
76
|
+
});
|
|
77
|
+
}
|
|
69
78
|
}
|
|
70
79
|
else if (operation === 'connect') {
|
|
71
80
|
try {
|
package/package.json
CHANGED