Socket.IO teilt sich den HTTP-Port statt eines eigenen Servers auf 3001
Der Socket.IO-Server lief als zweiter Server auf Port 3001 und brauchte
deswegen cors: { origin: "*" }; die Clients bauten ihre Verbindungs-URL aus
window.location.hostname und dem festen Port zusammen.
Er wird jetzt ohne eigenen Port erzeugt und in bin/www per io.attach() an den
bestehenden HTTP-Server gehaengt. Erzeugen und Anhaengen sind getrennt, weil das
Modul beim Laden der Routen ausgewertet wird, also bevor der HTTP-Server
existiert. Die Clients rufen nur noch io() ohne Argument auf und verbinden sich
damit zur Herkunft der Seite zurueck.
Damit entfallen der zweite Port, die CORS-Ausnahme und eine moegliche zweite
Firewall-Regel auf dem Pi. Verifiziert: Port 3001 lauscht nicht mehr, alle
Events (score, timerDurationLeft, timerEnded, scoreSideswitch, refresh) kommen
ueber Port 3000 an, Reconnect funktioniert.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
parent
cd4877bdd2
commit
2a1e0904e8
7 changed files with 36 additions and 17 deletions
|
|
@ -7,6 +7,7 @@
|
|||
var app = require('../app');
|
||||
var debug = require('debug')('scoreboard:server');
|
||||
var http = require('http');
|
||||
var io = require('../controllers/socketio');
|
||||
|
||||
/**
|
||||
* Get port from environment and store in Express.
|
||||
|
|
@ -21,6 +22,12 @@ app.set('port', port);
|
|||
|
||||
var server = http.createServer(app);
|
||||
|
||||
/**
|
||||
* Attach Socket.IO to the same server, so it shares the HTTP port.
|
||||
*/
|
||||
|
||||
io.attach(server);
|
||||
|
||||
/**
|
||||
* Listen on provided port, on all network interfaces.
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue