fix(api): use server.listen instead of app.listen for WebSocket support
- server.ts: switch from app.listen() to server.listen() so WebSocket upgrade handler is on the same server as HTTP requests - lobbyService: add host as first player on lobby creation - ws-client: guard against reconnect when already connecting - ws-provider: skip connect if already connected
This commit is contained in:
parent
974646ebfb
commit
540155788a
4 changed files with 14 additions and 2 deletions
|
|
@ -9,6 +9,6 @@ const server = createServer(app);
|
|||
|
||||
setupWebSocket(server);
|
||||
|
||||
app.listen(PORT, () => {
|
||||
server.listen(PORT, () => {
|
||||
console.log(`Server listening on port ${PORT}`);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -28,7 +28,9 @@ export const createLobby = async (hostUserId: string): Promise<Lobby> => {
|
|||
for (let i = 0; i < MAX_CODE_ATTEMPTS; i++) {
|
||||
const code = generateLobbyCode();
|
||||
try {
|
||||
return await createLobbyModel(code, hostUserId);
|
||||
const lobby = await createLobbyModel(code, hostUserId);
|
||||
await addPlayer(lobby.id, hostUserId, MAX_LOBBY_PLAYERS);
|
||||
return lobby;
|
||||
} catch (err) {
|
||||
if (isUniqueViolation(err)) continue;
|
||||
throw err;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue