Update Socket.IO deployment documentation and backend server configuration
This commit revises the deployment documentation for Socket.IO, emphasizing the need to restart the backend server for HTTPS support on port 3051. It introduces a new diagnostic script to check SSL certificate existence, server accessibility, and port status. Additionally, the backend server configuration is updated to ensure it listens on all interfaces (0.0.0.0), enhancing accessibility. These changes improve clarity and troubleshooting guidance for deploying Socket.IO over HTTPS.
This commit is contained in:
84
backend/scripts/checkSocketIOServer.js
Normal file
84
backend/scripts/checkSocketIOServer.js
Normal file
@@ -0,0 +1,84 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
* Prüft, ob der Socket.IO HTTPS-Server auf Port 3051 läuft
|
||||
*/
|
||||
|
||||
import https from 'https';
|
||||
import { readFileSync } from 'fs';
|
||||
|
||||
const httpsPort = process.env.HTTPS_PORT || 3051;
|
||||
|
||||
console.log(`🔍 Prüfe Socket.IO HTTPS-Server auf Port ${httpsPort}...\n`);
|
||||
|
||||
// Prüfe, ob Zertifikate existieren
|
||||
try {
|
||||
const keyPath = '/etc/letsencrypt/live/tt-tagebuch.de/privkey.pem';
|
||||
const certPath = '/etc/letsencrypt/live/tt-tagebuch.de/fullchain.pem';
|
||||
|
||||
readFileSync(keyPath);
|
||||
readFileSync(certPath);
|
||||
console.log('✅ SSL-Zertifikate gefunden');
|
||||
} catch (err) {
|
||||
console.error('❌ SSL-Zertifikate nicht gefunden:', err.message);
|
||||
console.error(' Erwartete Pfade:');
|
||||
console.error(' - /etc/letsencrypt/live/tt-tagebuch.de/privkey.pem');
|
||||
console.error(' - /etc/letsencrypt/live/tt-tagebuch.de/fullchain.pem');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Prüfe, ob Port geöffnet ist
|
||||
import { exec } from 'child_process';
|
||||
import { promisify } from 'util';
|
||||
|
||||
const execAsync = promisify(exec);
|
||||
|
||||
try {
|
||||
const { stdout } = await execAsync(`netstat -tlnp 2>/dev/null | grep :${httpsPort} || ss -tlnp 2>/dev/null | grep :${httpsPort} || echo "Port nicht gefunden"`);
|
||||
if (stdout.includes(':' + httpsPort)) {
|
||||
console.log(`✅ Port ${httpsPort} ist geöffnet und lauscht`);
|
||||
console.log(` ${stdout.trim()}`);
|
||||
} else {
|
||||
console.log(`❌ Port ${httpsPort} ist nicht geöffnet oder lauscht nicht`);
|
||||
console.log(' → Backend-Server muss neu gestartet werden');
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('⚠️ Konnte Port-Status nicht prüfen:', err.message);
|
||||
}
|
||||
|
||||
// Versuche Verbindung zum Server
|
||||
console.log(`\n🔌 Versuche Verbindung zu https://localhost:${httpsPort}/socket.io/...`);
|
||||
|
||||
const options = {
|
||||
hostname: 'localhost',
|
||||
port: httpsPort,
|
||||
path: '/socket.io/?EIO=4&transport=polling',
|
||||
method: 'GET',
|
||||
rejectUnauthorized: false
|
||||
};
|
||||
|
||||
const req = https.request(options, (res) => {
|
||||
console.log(`✅ Verbindung erfolgreich! Status: ${res.statusCode}`);
|
||||
res.on('data', (chunk) => {
|
||||
console.log(` Response: ${chunk.toString().substring(0, 100)}...`);
|
||||
});
|
||||
res.on('end', () => {
|
||||
console.log('\n✅ Socket.IO HTTPS-Server läuft korrekt!');
|
||||
});
|
||||
});
|
||||
|
||||
req.on('error', (err) => {
|
||||
console.error(`❌ Verbindung fehlgeschlagen: ${err.message}`);
|
||||
console.error(' → Backend-Server läuft möglicherweise nicht');
|
||||
console.error(' → Oder HTTPS-Server wurde nicht gestartet');
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
req.setTimeout(5000, () => {
|
||||
console.error('❌ Timeout beim Verbindungsversuch');
|
||||
req.destroy();
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
req.end();
|
||||
|
||||
@@ -283,7 +283,7 @@ app.get('*', (req, res) => {
|
||||
// Initialisiere Socket.IO auf HTTPS-Server
|
||||
initializeSocketIO(httpsServer);
|
||||
|
||||
httpsServer.listen(httpsPort, () => {
|
||||
httpsServer.listen(httpsPort, '0.0.0.0', () => {
|
||||
console.log(`🚀 HTTPS-Server für Socket.IO läuft auf Port ${httpsPort}`);
|
||||
});
|
||||
} catch (err) {
|
||||
|
||||
Reference in New Issue
Block a user