TL;DR: Discourse gives “Error Embedding” regardless of which hosts I allow in Embedding settings.
I have a published site at foo.com which embeds comments from the Discourse forum at forum.foo.com, which his working fine. When going to e.g. https://foo.com/blog/2019-11-22/foo-0.9.6-released , I see the embedded comments just fine. In this case, the script code for the embedding looks like this in the page’s source:
<div id='discourse-comments'></div>
<script type="text/javascript">
DiscourseEmbed = { discourseUrl: 'https://forum.foo.com/', discourseEmbedUrl: 'https://foo.com/blog/2019-11-22/foo-0.9.6-released' };
(function() {
var d = document.createElement('script'); d.type = 'text/javascript'; d.async = true;
d.src = DiscourseEmbed.discourseUrl + 'javascripts/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(d);
})();
</script>
I also have a development version of the site running on my local machine at localhost, where I have problems with the embedding - it keeps giving me “Error Embedding” instead of comments inside the HTML produced and returned by the forum. That is, I see the forum’s logo and a link to it in the top-right of the embedding area, but instead of listing comments I just get that error message.
When going to e.g. http://localhost:1313/blog/2019-11-22-foo-0.9.6-released/ , which is the equivalent page to the production site, the script code for the embedding looks like this in the page’s source:
<div id='discourse-comments'></div>
<script type="text/javascript">
DiscourseEmbed = { discourseUrl: 'https://forum.foo.com/', discourseEmbedUrl: 'http://localhost:1313/blog/2019-11-22-foo-0.9.6-released/' };
(function() {
var d = document.createElement('script'); d.type = 'text/javascript'; d.async = true;
d.src = DiscourseEmbed.discourseUrl + 'javascripts/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(d);
})();
</script>
I tried it both with and without the trailing / in the discourseEmbedUrl
setting, it makes no difference.
I do not have direct access to the server on which the forum runs, but I have gone into the admin panel of the forum and tried adding a bunch of host allows in the embedding settings. The current settings, for the production site which works with embedding, are:
"Allowed Hosts", "Class Name", "Path Whitelist", "Post to Category"
foo.com, <empty>, /blog/.*, blog
What I’ve added to make it work for my localhost development version of the site is:
"Allowed Hosts", "Class Name", "Path Whitelist", "Post to Category"
localhost, <empty>, /blog/.*, blog
localhost:1313, <empty>, /blog/.*, blog
<my external/public IP as seen by the forum server>, <empty>, /blog/.*, blog
<my external/public IP as seen by the forum server>:1313, <empty>, /blog/.*, blog
But neither of this makes it work, I just keep getting the same “Error Embedding” message.
I’m reluctant to dig into the source code and try to debug this, I’d rather get some input as to what Discource is checking when it determines that it should generate that error message. Can someone tell me that, and how to fix this? Should be pretty straight forward, but Discourse is acting like a black box here.
I have read all of Embedding Discourse Comments via Javascript but it doesn’t give more useful information.