Update Apache and backend configuration for direct Socket.IO HTTPS support
This commit modifies the Apache configuration to reflect that Socket.IO now runs directly on HTTPS port 3051, eliminating the need for Apache proxying. Additionally, the backend server setup is updated to create an HTTPS server for Socket.IO, including error handling for SSL certificate loading. The frontend service is also adjusted to connect to the new HTTPS endpoint, ensuring compatibility with the updated architecture.
This commit is contained in:
@@ -2,6 +2,8 @@ import express from 'express';
|
||||
import path from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
import { createServer } from 'http';
|
||||
import https from 'https';
|
||||
import fs from 'fs';
|
||||
import sequelize from './database.js';
|
||||
import cors from 'cors';
|
||||
import { initializeSocketIO } from './services/socketService.js';
|
||||
@@ -262,15 +264,34 @@ app.get('*', (req, res) => {
|
||||
// Start scheduler service
|
||||
schedulerService.start();
|
||||
|
||||
// Erstelle HTTP-Server für Socket.IO
|
||||
// Erstelle HTTP-Server für API
|
||||
const httpServer = createServer(app);
|
||||
|
||||
// Initialisiere Socket.IO
|
||||
initializeSocketIO(httpServer);
|
||||
|
||||
httpServer.listen(port, () => {
|
||||
console.log(`🚀 Server läuft auf Port ${port}`);
|
||||
console.log(`🚀 HTTP-Server läuft auf Port ${port}`);
|
||||
});
|
||||
|
||||
// Erstelle HTTPS-Server für Socket.IO (direkt mit SSL)
|
||||
const httpsPort = process.env.HTTPS_PORT || 3051;
|
||||
try {
|
||||
const httpsOptions = {
|
||||
key: fs.readFileSync('/etc/letsencrypt/live/tt-tagebuch.de/privkey.pem'),
|
||||
cert: fs.readFileSync('/etc/letsencrypt/live/tt-tagebuch.de/fullchain.pem')
|
||||
};
|
||||
|
||||
const httpsServer = https.createServer(httpsOptions, app);
|
||||
|
||||
// Initialisiere Socket.IO auf HTTPS-Server
|
||||
initializeSocketIO(httpsServer);
|
||||
|
||||
httpsServer.listen(httpsPort, () => {
|
||||
console.log(`🚀 HTTPS-Server für Socket.IO läuft auf Port ${httpsPort}`);
|
||||
});
|
||||
} catch (err) {
|
||||
console.error('⚠️ HTTPS-Server konnte nicht gestartet werden:', err.message);
|
||||
console.log(' → Socket.IO läuft auf HTTP-Server (nur für Entwicklung)');
|
||||
// Fallback: Socket.IO auf HTTP-Server
|
||||
initializeSocketIO(httpServer);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Unable to synchronize the database:', err);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user