mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-08-21 04:45:17 +00:00
Merge pull request #2798 from khassel/cors
This commit is contained in:
@@ -111,8 +111,17 @@ const WeatherProvider = Class.extend({
|
||||
this.delegate.updateAvailable(this);
|
||||
},
|
||||
|
||||
getCorsUrl: function () {
|
||||
if (this.config.mockData || typeof this.config.useCorsProxy === "undefined" || !this.config.useCorsProxy) {
|
||||
return "";
|
||||
} else {
|
||||
return location.protocol + "//" + location.host + "/cors?url=";
|
||||
}
|
||||
},
|
||||
|
||||
// A convenience function to make requests. It returns a promise.
|
||||
fetchData: function (url, method = "GET", data = null) {
|
||||
fetchData: function (url, method = "GET", type = "json") {
|
||||
url = this.getCorsUrl() + url;
|
||||
const getData = function (mockData) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
if (mockData) {
|
||||
@@ -125,7 +134,11 @@ const WeatherProvider = Class.extend({
|
||||
request.onreadystatechange = function () {
|
||||
if (this.readyState === 4) {
|
||||
if (this.status === 200) {
|
||||
resolve(JSON.parse(this.response));
|
||||
if (type === "xml") {
|
||||
resolve(this.responseXML);
|
||||
} else {
|
||||
resolve(JSON.parse(this.response));
|
||||
}
|
||||
} else {
|
||||
reject(request);
|
||||
}
|
||||
|
Reference in New Issue
Block a user