From cf7d7e500f60744c27bd71f70840eb7e134e437c Mon Sep 17 00:00:00 2001 From: Laurent Date: Sat, 17 Feb 2024 19:14:14 +0000 Subject: [PATCH] Va chercher l'url du broker en variable de configuration --- .gitignore | 3 +++ src/config.js.example | 4 ++++ src/services/mqttService.js | 4 +++- 3 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 src/config.js.example diff --git a/.gitignore b/.gitignore index 8ee54e8..3d551ca 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,6 @@ coverage *.sw? *.tsbuildinfo + +# Local configuration file +/src/config.js \ No newline at end of file diff --git a/src/config.js.example b/src/config.js.example new file mode 100644 index 0000000..559f60b --- /dev/null +++ b/src/config.js.example @@ -0,0 +1,4 @@ +// config.js +export default { + mqttBrokerUrl: 'ws://localhost:9001' +}; diff --git a/src/services/mqttService.js b/src/services/mqttService.js index 08389f3..ce3a9ac 100644 --- a/src/services/mqttService.js +++ b/src/services/mqttService.js @@ -1,7 +1,9 @@ import mqtt from 'mqtt'; +import config from '@/config.js'; +const mqttBrokerUrl = config.mqttBrokerUrl; // Créer une instance de client MQTT -const client = mqtt.connect('ws://localhost:9001'); +const client = mqtt.connect(mqttBrokerUrl); // Fonction pour publier un message sur un topic MQTT export function publishMessage(topic, message) {