Read the statement by Michael Teeuw here.
Testing my module, it is stuck loading
-
@sdetweil ugh, well that did not do it unfortunately. I’m not sure what to do now. It recommends setting the requests mode to ‘no-cors’. Is that something that might work here?
-
@l0zarus CORS is controlled by the server side, NOTHING the client can do except change the capability
there used to be free services where you could send the request to them and they would forward (from a known address) and send the response back to you
a CORS proxy, most of those have gone away or are no longer free.we’ve added a cors safe fetch (we think) to the MM system
see ~/MagicMirror/js/server_functions.js
( I have tried to break that into understandable reusable sections below )u change your url request to this cors_url
let header_stuff_if_any="sendheaders=header1:value1,header2:value2&expectedheaders=header1,header2" // empty string, "", if no headers let original_url="http://www.test.com/path?param1=value1" ----------- let_cors_url= "http://"+ // use the config.address value, unless its "0.0.0.0", then use "localhost" config.address==="0.0.0.0"?"localhost":config.address + ":" +config.port+ "/cors?"+ header_stuff +"&url="+ original_url
and we will send it, and return the response to your fetch
-
@sdetweil I’m struggling to understand the first part. I don’t think there is any header stuff that I know of? the url is based on this format: https://api.seatgeek.com/2/events?client_id=MYCLIENTID&client_secret=MYCLIENTSECRET with other stuff added as you saw in my source code in the original post.
honestly the whole thing is a bit confusing to me. I’m not sure where it is supposed to go… as part of where I define the URL variable?
-
@l0zarus ok, no headers set it to “”
you use that code to build your fetch url (and put it in the original_url variable)
I just created the JS code to do the build from the parts
the comment in the linked file just doesn’t help me at all…and when you execute the fetch, it sends it to magic mirror code that forwards on supposedly to avoid the cors problem…
-
@sdetweil I’m going to try to fill it out like a template, let me know if I’m following.
let header = "", let original_url = "https://api.seatgeek.com/2/events?client_id=MYCLIENTID&client_secret=MYCLIENTSECRET " let cors_url = "http://" + config.address==="IP ADDRESS HERE"?"localhost":config.address + ":" + config.port + "/cors?" + header + "&url=" + original_url
and then I
fetch(cors_url)
?Is this right?
-
@l0zarus said in Testing my module, it is stuck loading:
Is this right?
yes
almost …
"IP ADDRESS HERE"
MUST be
"0.0.0.0"
(which is the MM value for listen on any network adapter)
-
```
// this next block is to deal with a CORS permissions issue with the API
let header = “”;// this is the API call url let original_url = "http://api.seatgeek.com/2/events?lat=" + self.config.latitude + "&lon=" + self.config.longitude + "&per_page=" + self.config.eventCount + "&datetime_utc.gte=" + today + "&datetime_utc.lte=" + oneweek + "&range=" + self.config.range + "&type=concert" + "&client_id=" + self.config.clientID + "&client_secret=" + self.config.clientSecret; // this is the cors URL let cors_url = "http://" + config.address==="0.0.0.0"?"localhost":config.address + ":" + config.port + "/cors?" + header + "&url=" + original_url;
-
@l0zarus looks good
-
@sdetweil I got a new console error:
-
@l0zarus you did NOT add let config= right? (or var, or const)
config is already defined for you
this.config is the stuff from your module entry
config. is ALL the config.js