From b6e4bd5c01af37b4fb4e85e0fcdb73c7abc48cf3 Mon Sep 17 00:00:00 2001 From: hoeppner-dataport Date: Wed, 3 Apr 2024 17:09:20 +0200 Subject: [PATCH] add default for servername in success actions --- src/socket/socket/socket.gateway.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/socket/socket/socket.gateway.ts b/src/socket/socket/socket.gateway.ts index 69dbc11..a3b637f 100644 --- a/src/socket/socket/socket.gateway.ts +++ b/src/socket/socket/socket.gateway.ts @@ -9,6 +9,8 @@ import { import { Server } from 'socket.io'; import { Logger } from '@nestjs/common'; +const server = process.env.HOSTNAME ?? 'localhost'; + @WebSocketGateway({ path: '/poc-board-collaboration-server', cors: { @@ -44,7 +46,7 @@ export class SocketGateway handleUpdateCard(client: any, data: any) { this.logger.log(`Message received from client id: ${client.id}`); this.logger.debug(`Payload: ${data}`); - const responsePayload = { ...data, server: process.env.HOSTNAME }; + const responsePayload = { ...data, server }; client.broadcast.emit('update-card-success', responsePayload); client.emit('update-card-success', responsePayload); } @@ -53,7 +55,7 @@ export class SocketGateway handleLockCard(client: any, data: any) { this.logger.log(`Message received from client id: ${client.id}`); this.logger.debug(`Payload: ${data}`); - const responsePayload = { ...data, server: process.env.HOSTNAME }; + const responsePayload = { ...data, server }; client.broadcast.emit('lock-card-success', responsePayload); client.emit('lock-card-success', responsePayload); } @@ -62,7 +64,7 @@ export class SocketGateway handleUnlockCard(client: any, data: any) { this.logger.log(`Message received from client id: ${client.id}`); this.logger.debug(`Payload: ${data}`); - const responsePayload = { ...data, server: process.env.HOSTNAME }; + const responsePayload = { ...data, server }; client.broadcast.emit('unlock-card-success', responsePayload); client.emit('unlock-card-success', responsePayload); } @@ -71,7 +73,7 @@ export class SocketGateway handleDeleteCard(client: any, data: any) { this.logger.log(`Message received from client id: ${client.id}`); this.logger.debug(`Payload: ${data}`); - const responsePayload = { ...data, server: process.env.HOSTNAME }; + const responsePayload = { ...data, server }; client.broadcast.emit('delete-card-success', responsePayload); client.emit('delete-card-success', responsePayload); } @@ -86,7 +88,7 @@ export class SocketGateway ...data, cardId, text: '', - server: process.env.HOSTNAME, + server, }; this.logger.debug(`Response Payload: ${JSON.stringify(responsePayload)}`); @@ -98,7 +100,7 @@ export class SocketGateway handleMoveCard(client: any, data: any) { this.logger.log(`Message received from client id: ${client.id}`); this.logger.debug(`Payload: ${data}`); - const responsePayload = { ...data, server: process.env.HOSTNAME }; + const responsePayload = { ...data, server }; client.broadcast.emit('move-card-success', responsePayload); } @@ -106,7 +108,7 @@ export class SocketGateway handleMoveColumn(client: any, data: any) { this.logger.log(`Message received from client id: ${client.id}`); this.logger.debug(`Payload: ${data}`); - const responsePayload = { ...data, server: process.env.HOSTNAME }; + const responsePayload = { ...data, server }; client.broadcast.emit('move-column-success', responsePayload); } }