try to fix this spaghetti of a code

This commit is contained in:
Frederik Spirgi
2026-09-09 11:02:31 +02:00
parent c0eb11c8d4
commit 45eef9ef5c
4 changed files with 7 additions and 6 deletions
+3 -2
View File
@@ -1,4 +1,4 @@
const http = require('node:http'); const http = require('node:http');
const {configuration} = require('./lib/config'); const {configuration} = require('./lib/config');
const {createRepository} = require('./lib/repository'); const {createRepository} = require('./lib/repository');
const {createSessionService} = require('./lib/sessions'); const {createSessionService} = require('./lib/sessions');
@@ -33,7 +33,8 @@ async function createApplication(options = {}) {
if (require.main === module) { if (require.main === module) {
require('dotenv').config(); require('dotenv').config();
createApplication().then(async application => { createApplication().then(async application => {
const address = await application.listen(); let address;
try {address = await application.listen();} catch (error) {await application.close(); throw error;}
console.log(`Server listening at http://${address.address}:${address.port}`); console.log(`Server listening at http://${address.address}:${address.port}`);
for (const signal of ['SIGINT', 'SIGTERM']) process.once(signal, () => application.close().catch(error => {console.error(error); process.exitCode = 1;})); for (const signal of ['SIGINT', 'SIGTERM']) process.once(signal, () => application.close().catch(error => {console.error(error); process.exitCode = 1;}));
}).catch(error => {console.error(error.message); process.exitCode = 1;}); }).catch(error => {console.error(error.message); process.exitCode = 1;});
+1 -1
View File
@@ -37,7 +37,7 @@ function createLobbyService(repository, config) {
const membershipMutation = ['lobby:create', 'lobby:join', 'lobby:leave'].includes(message.type); const membershipMutation = ['lobby:create', 'lobby:join', 'lobby:leave'].includes(message.type);
return queue.run([...(membershipMutation ? ['membership'] : []), ...(username ? [`account:${username}`] : []), return queue.run([...(membershipMutation ? ['membership'] : []), ...(username ? [`account:${username}`] : []),
...(message.lobbyId ? [`lobby:${message.lobbyId}`] : [])], async () => { ...(message.lobbyId ? [`lobby:${message.lobbyId}`] : [])], async () => {
const id = `${username || 'system'}:${message.requestId}`; const id = `${username ? `user:${username}` : 'system'}:${message.requestId}`;
const fingerprint = hash(JSON.stringify(canonical(message))); const fingerprint = hash(JSON.stringify(canonical(message)));
const prior = await repository.command(id); const prior = await repository.command(id);
if (prior) { if (prior) {
+2 -2
View File
@@ -45,11 +45,11 @@ window.RealtimeClient = class extends EventTarget {
} }
this.dispatchEvent(new CustomEvent('message', {detail: message})); this.dispatchEvent(new CustomEvent('message', {detail: message}));
}); });
socket.addEventListener('error', () => this.status('Connection interrupted. Reconnecting…')); socket.addEventListener('error', () => this.status('Connection interrupted. Reconnecting...'));
socket.addEventListener('close', async event => { socket.addEventListener('close', async event => {
clearTimeout(timeout); this.ready = false; clearTimeout(timeout); this.ready = false;
if (this.stopped) return; if (this.stopped) return;
this.status('Connection interrupted. Reconnecting…'); this.status('Connection interrupted. Reconnecting...');
if (event.code === 1008 && /Session/.test(event.reason)) { if (event.code === 1008 && /Session/.test(event.reason)) {
this.close(); localStorage.removeItem('activeLobbyId'); location.assign('/login'); return; this.close(); localStorage.removeItem('activeLobbyId'); location.assign('/login'); return;
} }
+1 -1
View File
@@ -101,7 +101,7 @@ document.addEventListener("DOMContentLoaded", () => {
if (winner) { if (winner) {
const heading = document.createElement("h2"); const heading = document.createElement("h2");
heading.textContent = `Winner: ${winner}`; heading.textContent = `Payout recipients: ${winner}`;
showdownPanel.appendChild(heading); showdownPanel.appendChild(heading);
} }