Making discourseEmbedURL match expected topic requirements

I’m trying to utilize discourse in order to provide embedded discussions for an existing web site. The urls of the existing site are not fliexible and I’m trying to work around restrictions on discourse for topic length. For testing I have the following web page at ‘http://localhost:6543/cases/88’. I’m using a hosted site and have correctly setup the DNS alias to redirect back to the discourse subdomain. I’ve added ‘localhost:6543’ to my discourse site with a default category( which already exists) and am using the following javascript in my html page:

 <script type="text/javascript">
     $(function()
     { 
         var DiscourseEmbed = { discourseUrl: 'http://citadel-discussion.lexmachina.com/', 
                           discourseEmbedUrl: 'http://localhost:6543/cases/88' };
         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>

The response I get from discourse is

404 Not Found

The resource could not be found.

/cases/undefinedembed/comments

My assumption here is that the url components are not adequate for a new topic. Since I can’t create any topic with the disourse admin UI that is under a certainly length.

How might I utilize this url to automatically create topics in discourse?
Must the url string in discourseEmbedUrl match the actual url of the page?

Thanks for your help.

  • Jeff

I think the problem is your localhost:6543 is not accessible (it will not accessible if your localhost installation is done in your PC) from the instance where discourse installed. try with live domain name instead of localhost. If it worked correctly Discourse will create new topic automatically when the embedded page loaded. You don’t need to do anything else.

1 Like

Thanks Vinoth. I’m testing that idea on a public site, but now I’m running into an error loading the embed.js. I may not have mentioned, but we’re also using google oauth2 to control access to this site. I’ve added https://meda.discourse.org/auth/google_oauth2/callback for the login callback but it looks like we may need to host the embed.js locally unless there are other suggestions.
Since I’m testing in Safari, I tried changing the discourseUrl to ‘https://citadel-discussion.lexmachina.com/’ so that both would be in the same https domain, but that resulted in an ERR_CONNECTION_REFUSED response.

  • Jeff

[blocked] The page at https://citadel-gauth.stage.lexmachina.com/cases/88 was not allowed to run insecure content from http://citadel-discussion.lexmachina.com/javascripts/embed.js.

BTW, the update javascript looks like this:

<script type="text/javascript">
    $(function()
    {

        var DiscourseEmbed = { discourseUrl: 'https://citadel-discussion.lexmachina.com/',
                          discourseEmbedUrl: 'https://citadel-gauth.stage.lexmachina.com/cases/88' };
        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>

BTW, what exactly is http error code 443: Connection Refused ?

This is what I get from trying to load embed.js from an https url:

$curl https://citadel-discussion.lexmachina.com/javascripts/embed.js

Whereas a non-https connection loads embed.js just fine, but then conflicts with the https connection to the html page. I’m not sure how you’d get a successful https connection to a DNS alias since whatever cert you have for ‘lexmachina.bydiscourse.com’ would not include ‘citadel-discussion.lexmachina’

May be you don’t have proper SSL certificates. How can you tell more details about how exactly you using your lexmachina.bydiscourse.com and citadel-discussion.lexmachina websites?

Are you just pointed citadel-discussion.lexmachina CNAME into lexmachina.bydiscourse.com? I tried to open this url lexmachina.bydiscourse.com on my browser and am unable to reach it.

Okay I was wondering about that, but these are just domains used to access separate discourse forum that we are wanting to use. One is an alias and the other is owned by disourse.

How does someone use an embedded discourse site on a protected page served from https?

I don’t think providing an ssl cert for the alias domain alone would work. I did consider copying and hosting the embed.js file from our server, but it conflicts with our gulp jslint requirements and that quickly proved untenable. I also thought of trying to proxy it though our nginx config might be an option, but I’d much rather see the ability to load embed.js from any https supported site.

Or more directly, can I get an https url for my discourse forum ( ‘lexmachina.bydiscourse.com’) ?