Read the statement by Michael Teeuw here.
Switch URL based on value
-
@htilburgs
Just for your referenceconst ip_a = "..." const ip_b = "..." const apiQuery = (index, url) => { if (!url) return Promise.reject({ index, reason: 'url is not defined' }) return new Promise((resolve, reject) => { try { fetch(url) .then(response => response.json()) .then(data => { resolve({ index, value: data }) }) .catch(error => { reject({ index, reason: error }) }) } catch (error) { reject({ index, reason: error }) } }) } const queries = [] queries.push(apiQuery('A', ip_a)) queries.push(apiQuery('B', ip_b)) Promise.allSettled(queries).then((results) => { console.log('All jobs are done') results.values().forEach((result) => { if (result.status === 'fulfilled') { console.log(`Index: ${result.value.index}, Value:`, result.value.value) } else { console.log(`Index: ${result.reason.index}, Error:`, result.reason.reason) } }) })
-
@htilburgs hm… looks ok, I would use the developer window sources tab to debug the code and look at the variables… (mouse over name usage will show contents)
-
@sdetweil
In the console - sources it says:Uncaught SyntaxError: Unexpected token 'if'
-
@htilburgs well, if the code breaks, then …
so, look at that line and see what is missing from before it
a quick way to find syntax errors
in the module folder, run the pre-compiler to check for errors
node -c modulename.js
(or any js file)
-
@sdetweil
Meanwhile I was doing this, and I found the error (stupid me)start: function () { Log.info("Starting module: " + this.name); requiresVersion: "2.9.0"; // Set locales if (this.config.P1_IP != null) { this.urlP1 = "http://" + this.config.P1_IP + "/api/v1/data/"; } else { this.urlP1 = "https://dummyjson.com/c/7e24-36ab-48e0-a96d"; } if (this.config.WM_IP != null) { this.urlWM = "http://" + this.config.WM_IP + "/api/v1/data/"; } else { this.urlWM = "https://dummyjson.com/c/704a-9a96-4845-bc72"; } // this.urlP1 = "http://" + this.config.P1_IP + "/api/v1/data/"; // this.urlWM = "http://" + this.config.WM_IP + "/api/v1/data/"; this.MHW_P1 = []; // <-- Create empty MHW_P1 array this.MHW_WM = []; // <-- Create empty MHW_WM array this.scheduleUpdate(); // <-- When the module updates (see below) },
The line with "requiresVersion: “2.9.0”; " was ending with an “,” instead of “;”
without the “if” statement, I don’t get a failure with a “,”
So changed it now into “;” and everythins seems to work.
I continue testing.@MMRIZE Thanks for the alternative way. I’m going to look into it.
So with the “promise” statement, it looks like I can eleminate the node_helper.js -
@htilburgs said in Switch URL based on value:
The line with "requiresVersion: “2.9.0”; " was ending with an “,” instead of “;”
requiresVersion should be outside the start function… (and then needs a trailing comma
-
@htilburgs said in Switch URL based on value:
So with the “promise” statement, it looks like I can eleminate the node_helper.js
correct, now that electron (and nodejs) have fetch built in(since node 18), you don’t NEED to use node_helper to do it
-