diff --git a/src/lib/server/socket.ts b/src/lib/server/socket.ts index 4cb6ea3..6b90ac5 100644 --- a/src/lib/server/socket.ts +++ b/src/lib/server/socket.ts @@ -11,17 +11,13 @@ export const initSocketIO = (httpServer: HTTPServer): Promise => { if (!io) { console.log('Initializing Socket.IO server...'); io = new Server(httpServer, { - path: '/socket.io/', + path: '/socket.io', cors: { origin: dev ? ['http://localhost:3000'] : ['https://youtubepedia.barron.agency'], methods: ['GET', 'POST'], credentials: true }, - transports: ['websocket', 'polling'], - pingTimeout: 60000, - pingInterval: 25000, - connectTimeout: 45000, - allowEIO3: true + transports: ['websocket', 'polling'] }); io.on('connection', (socket) => { @@ -33,12 +29,8 @@ export const initSocketIO = (httpServer: HTTPServer): Promise => { console.log(`User ${userId} joined their room`); } - socket.on('error', (error) => { - console.error('Socket error:', error); - }); - - socket.on('disconnect', (reason) => { - console.log(`Client disconnected (${reason})`, socket.id); + socket.on('disconnect', () => { + console.log('Client disconnected', socket.id); }); }); diff --git a/src/lib/socket.ts b/src/lib/socket.ts index 83cb13f..5ba1b9e 100644 --- a/src/lib/socket.ts +++ b/src/lib/socket.ts @@ -3,13 +3,14 @@ import { io, type Socket } from 'socket.io-client'; export const initSocket = (userId: string): Socket | null => { if (browser) { - // Kein expliziter Port - nutze den gleichen Port wie die App - const socket = io(window.location.origin, { + const socketUrl = `${window.location.protocol}//${window.location.hostname}:3001`; + + const socket = io(socketUrl, { auth: { userId }, reconnection: true, reconnectionDelay: 1000, reconnectionAttempts: 5, - path: '/socket.io' // Muss mit Server-Path übereinstimmen + path: '/socket.io' }); socket.on('connect', () => { diff --git a/vite.config.ts b/vite.config.ts index 3f993d7..76420d1 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -11,15 +11,10 @@ const webSocketServer = { const io = new Server(server.httpServer, { cors: { - origin: ['http://localhost:3000', 'https://youtubepedia.barron.agency'], + origin: '*', methods: ['GET', 'POST'], - credentials: true, - allowedHeaders: ['Content-Type', 'Authorization'] - }, - path: '/socket.io', - transports: ['websocket', 'polling'], - pingTimeout: 60000, - pingInterval: 25000 + credentials: true + } } as Partial); io.on('connection', (socket) => { @@ -31,31 +26,16 @@ const webSocketServer = { console.log(`User ${userId} joined their room`); } - socket.on('error', (error) => { - console.error('Socket error:', error); - }); - socket.on('disconnect', () => { console.log('Client disconnected', socket.id); }); }); - - io.engine?.on('connection_error', (err) => { - console.error('Connection error:', err); - }); } }; export default defineConfig({ plugins: [sveltekit(), webSocketServer], server: { - port: 3000, - host: true, - cors: true, - proxy: { - '/socket.io': { - target: 'ws://localhost:3000' - } - } + port: 3000 } });