fix cors problems with newsfeed articles (#2940)

solves #2840 as far as possible. There could still be errors on the
embedded iframe when the owner of the site has set `X-Frame-Options` or
`Access-Control-Allow-Origin` headers (as already mentioned in the
docs).
This commit is contained in:
Karsten Hassel
2022-10-17 21:38:08 +02:00
committed by GitHub
parent ad4dbd786a
commit 7bd944391e
4 changed files with 23 additions and 5 deletions

View File

@@ -42,6 +42,14 @@ Module.register("newsfeed", {
dangerouslyDisableAutoEscaping: false
},
getUrlPrefix: function (item) {
if (item.useCorsProxy) {
return location.protocol + "//" + location.host + "/cors?url=";
} else {
return "";
}
},
// Define required scripts.
getScripts: function () {
return ["moment.js"];
@@ -142,14 +150,19 @@ Module.register("newsfeed", {
sourceTitle: item.sourceTitle,
publishDate: moment(new Date(item.pubdate)).fromNow(),
title: item.title,
url: item.url,
url: this.getUrlPrefix(item) + item.url,
description: item.description,
items: items
};
},
getActiveItemURL: function () {
return typeof this.newsItems[this.activeItem].url === "string" ? this.newsItems[this.activeItem].url : this.newsItems[this.activeItem].url.href;
const item = this.newsItems[this.activeItem];
if (item) {
return typeof item.url === "string" ? this.getUrlPrefix(item) + item.url : this.getUrlPrefix(item) + item.url.href;
} else {
return "";
}
},
/**