diff --git a/apps/game-db-updater/src/mqttClient.ts b/apps/game-db-updater/src/mqttClient.ts index 0ca93df40..b20c6d5d2 100644 --- a/apps/game-db-updater/src/mqttClient.ts +++ b/apps/game-db-updater/src/mqttClient.ts @@ -4,40 +4,39 @@ import createDebugger from 'debug' let mqttClient: AsyncMqttClient type MqttConnectionOptions = { - host?: string - port?: number - username?: string - password?: string + host?: string + port?: number + username?: string + password?: string } const getMqttClient = async ( - connectionOptions?: MqttConnectionOptions, + connectionOptions?: MqttConnectionOptions, ): Promise => { - const debug = createDebugger('game-db-updater/mqttClient') - - if (!mqttClient) { - const host = - connectionOptions?.host ?? process.env.MQTT_HOST ?? 'localhost' - const port = - connectionOptions?.port ?? - parseInt(process.env.MQTT_PORT ?? '1883', 10) - const username = - connectionOptions?.username ?? process.env.MQTT_USERNAME ?? '' - const password = - connectionOptions?.password ?? process.env.MQTT_PASSWORD ?? '' - - debug( - `Existing MQTT client not found; creating one with the following options: host=${host}, port=${port}, username=${username}`, - ) - mqttClient = await connectAsync(`tcp://${host}`, { - password, - port, - username, - }) - } - - debug('Returning MQTT client') - return mqttClient + const debug = createDebugger('game-db-updater/mqttClient') + + if (!mqttClient) { + const host = connectionOptions?.host ?? process.env.MQTT_HOST ?? 'localhost' + const port = + connectionOptions?.port ?? parseInt(process.env.MQTT_PORT ?? '1883', 10) + const username = + connectionOptions?.username ?? process.env.MQTT_USERNAME ?? '' + const password = + connectionOptions?.password ?? process.env.MQTT_PASSWORD ?? '' + + debug( + `Existing MQTT client not found; creating one with the following options: host=${host}, port=${port}, username=${username}`, + ) + mqttClient = await connectAsync(`tcp://${host}`, { + password, + port, + username, + }) + } + + debug('Returning MQTT client') + + return mqttClient } export { getMqttClient }