diff --git a/server/broadcast.js b/server/broadcast.js index 05625cb..758ca58 100644 --- a/server/broadcast.js +++ b/server/broadcast.js @@ -1,5 +1,5 @@ import crypto from 'crypto'; -import { readFileSync, writeFileSync, appendFileSync } from 'fs'; +import { readFileSync, writeFileSync, appendFileSync, existsSync, mkdirSync } from 'fs'; import { join } from 'path'; import axios from 'axios'; @@ -125,9 +125,14 @@ function getConversationKey(user1, user2) { return [user1, user2].sort().join(':'); } -function logClientLogin(client) { +function logClientLogin(client, __dirname) { try { - const logPath = join(process.cwd(), 'logs', 'logins.log'); + const logsDir = join(__dirname, '../logs'); + // Erstelle logs-Verzeichnis falls es nicht existiert + if (!existsSync(logsDir)) { + mkdirSync(logsDir, { recursive: true }); + } + const logPath = join(logsDir, 'logins.log'); const logEntry = `${new Date().toISOString()},${client.userName},${client.country},${client.age},${client.gender}\n`; appendFileSync(logPath, logEntry, 'utf-8'); } catch (error) { @@ -135,9 +140,14 @@ function logClientLogin(client) { } } -function checkAndLogStart() { +function checkAndLogStart(__dirname) { try { - const logPath = join(process.cwd(), 'logs', 'starts.log'); + const logsDir = join(__dirname, '../logs'); + // Erstelle logs-Verzeichnis falls es nicht existiert + if (!existsSync(logsDir)) { + mkdirSync(logsDir, { recursive: true }); + } + const logPath = join(logsDir, 'starts.log'); const logEntry = `${new Date().toISOString()}\n`; appendFileSync(logPath, logEntry, 'utf-8'); } catch (error) { @@ -145,7 +155,7 @@ function checkAndLogStart() { } } -export function setupBroadcast(io) { +export function setupBroadcast(io, __dirname) { // Länderliste beim Start laden let countriesMap = {}; @@ -553,8 +563,8 @@ export function setupBroadcast(io) { socketConnected: client.socket ? client.socket.connected : false }); - logClientLogin(client); - checkAndLogStart(); + logClientLogin(client, __dirname); + checkAndLogStart(__dirname); // Benutzerliste an alle senden broadcastUserList(); diff --git a/server/index.js b/server/index.js index 571457d..04eb3bd 100644 --- a/server/index.js +++ b/server/index.js @@ -96,7 +96,7 @@ setupSEORoutes(app, __dirname); setupRoutes(app, __dirname); // Socket.IO-Handling -setupBroadcast(io); +setupBroadcast(io, __dirname); // In Production: Serviere auch die gebauten Client-Dateien // SPA-Fallback muss nach allen anderen Routen stehen