Trouble embedding Discourse as a comment engine using GitHub Pages and DigitalOcean


(Jason Taylor) #1

Hi all!

I followed the instructions on how to embed Discourse as a comment engine by @eviltrout and I’m having some issues that I can’t seem to resolve on my own. I’m hoping that someone here can point me in the right direction.

About the Setup

My domain points to a static GitHub Pages organization site baked with Jekyll. The root domain is configured, as per GitHub’s instructions, with two A records. The www sub-domain is configured with a CNAME record. Both the apex and sub-domain point to the same place.

My Discourse installation is using the DigitalOcean 1GB / Docker setup. The discourse sub-domain is configured with an A record that points to the IP of my droplet. I am using version 0.9.9.12 of Discourse.

Here is my Discourse embedding configuration:

Here is the client bit:

The Problem

When I push a new post to the blog, it takes forever to show up as a topic on Discourse. Yesterday, after completing the configuration, it took several hours for the one blog post we have to show up in Discourse. Today, after pushing two new blog posts at the same time, the first showed up almost immediately while it has been at least an hour and a half and the second post has yet to show up.

Additionally, when I visit a blog post that does not have a corresponding topic in Discourse, this is the result:

The Loading Discussion... message is displayed in the iFrame for a minute or two, then the above error is displayed in the console. I thought I read somewhere that when a post is visited, the topic would be automatically created if it doesn’t exist. I could be wrong about this.

Also, I don’t know if this is related or not, but when I type in my root domain, I notice that the browser will flash for a split second the www prefixed sub-domain. I read that GitHub will automatically create redirects between the apex and www sub-domain.

Any help would be greatly appreciated! Thanks :smile:


Embedding Content on a site with 'X-Frame-Options' to 'SAMEORIGIN'
(Jason Taylor) #2

I found this in the production.log. It occurs once for each post in the feed and it might be the reason that the posts aren’t importing.

exception: PrettyText::JavaScriptError
context: {:current_db=>"default", :current_hostname=>"discourse.domain.com"}
backtrace: at validateAttribute (/var/www/discourse/app/assets/javascripts/discourse/lib/markdown.js:31:40)
at sanitizeAttribs (/var/www/discourse/app/assets/javascripts/defer/html-sanitizer-bundle.js:2060:32)
at /var/www/discourse/app/assets/javascripts/defer/html-sanitizer-bundle.js:2169:32
at makeSaxParser.startTag (/var/www/discourse/app/assets/javascripts/defer/html-sanitizer-bundle.js:1860:24)
at parseStartTag (/var/www/discourse/app/assets/javascripts/defer/html-sanitizer-bundle.js:1719:9)
at parseCPS (/var/www/discourse/app/assets/javascripts/defer/html-sanitizer-bundle.js:1573:21)
at parse (/var/www/discourse/app/assets/javascripts/defer/html-sanitizer-bundle.js:1501:5)
at /var/www/discourse/app/assets/javascripts/defer/html-sanitizer-bundle.js:1464:14
at sanitizeWithPolicy (/var/www/discourse/app/assets/javascripts/defer/html-sanitizer-bundle.js:2201:33)
at sanitize (/var/www/discourse/app/assets/javascripts/defer/html-sanitizer-bundle.js:2216:12)
at Discourse.Markdown.sanitize (/var/www/discourse/app/assets/javascripts/discourse/lib/markdown.js:208:19)
at Discourse.Dialect.cook (/var/www/discourse/app/assets/javascripts/discourse/dialects/dialect.js:161:35)
at makeHtml (/var/www/discourse/app/assets/javascripts/discourse/lib/markdown.js:222:34)
at <eval>:1:44
/var/www/discourse/lib/pretty_text.rb:152:in `block in markdown'
/var/www/discourse/lib/pretty_text.rb:299:in `block in protect'
/var/www/discourse/lib/pretty_text.rb:297:in `synchronize'
/var/www/discourse/lib/pretty_text.rb:297:in `protect'
/var/www/discourse/lib/pretty_text.rb:133:in `markdown'
/var/www/discourse/lib/pretty_text.rb:172:in `cook'
/var/www/discourse/app/models/post_analyzer.rb:12:in `cook'
/var/www/discourse/app/models/post_analyzer.rb:104:in `cooked_document'
/var/www/discourse/app/models/post_analyzer.rb:49:in `raw_mentions'
/var/www/discourse/app/models/post.rb:133:in `block (2 levels) in <class:Post>'
/var/www/discourse/app/services/post_alerter.rb:135:in `extract_mentioned_users'
/var/www/discourse/app/services/post_alerter.rb:172:in `notify_post_users'
/var/www/discourse/app/services/post_alerter.rb:25:in `after_create_post'
/var/www/discourse/app/services/post_alerter.rb:5:in `post_created'
/var/www/discourse/lib/post_creator.rb:77:in `create'
/var/www/discourse/app/models/topic_embed.rb:40:in `block in import'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/database_statements.rb:201:in `block in transaction'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/database_statements.rb:209:in `within_new_transaction'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/database_statements.rb:201:in `transaction'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.4/lib/active_record/transactions.rb:208:in `transaction'
/var/www/discourse/app/models/topic_embed.rb:33:in `import'
/var/www/discourse/app/jobs/scheduled/poll_feed.rb:39:in `import_topic'
/var/www/discourse/app/jobs/scheduled/poll_feed.rb:33:in `block in import_topics'
/var/www/discourse/app/jobs/scheduled/poll_feed.rb:32:in `each'
/var/www/discourse/app/jobs/scheduled/poll_feed.rb:32:in `import_topics'
/var/www/discourse/app/jobs/scheduled/poll_feed.rb:26:in `poll_feed'
/var/www/discourse/app/jobs/scheduled/poll_feed.rb:16:in `execute'
/var/www/discourse/app/jobs/base.rb:131:in `block (2 levels) in perform'

(Manthan Mallikarjun) #3

Im not a ruby expert, but the log says:

Double check your config to make sure the hostname is set to the correct domain. (Im not sure if this will solve the problem).


(Jason Taylor) #4

Good eye! I changed that to read domain.com because I didn’t want a flood of people visiting right away. The log does indeed reflect my actual domain.


(Jason Taylor) #5

Found out that having a data-lightbox="group" attribute in an element causes the exception.


Data-lightbox="group" attribute causes exception
(Robin Ward) #6

Do you have a way we can reproduce this and fix it?


(Jason Taylor) #7

I think the only way to truly reproduce it would be to have Discourse poll a feed that contains a link element with the data-lightbox="group" attribute.

I was able to get a similar exception by doing the following.

  1. Run tail -f production.log on the server to get a glimpse of what’s going on
  2. Create a new topic with any title
  3. In the body of the topic place this <a href="somelink" data-lightbox="group">somelink</a>
  4. Post the topic

The server replies with an internal 500 server error box and there is a similar exception in the log:

https://gist.github.com/e05a6aaec5950101de07

In fact, it looks like the same exception, but without the javascript trace.

I don’t have time right now to figure out how to fix it, but I’ll look at it more in-depth later.


(Jason Taylor) #8

Ok, I figured out how to fix it and made the change to:

/var/www/discourse/app/assets/javascripts/discourse/lib/markdown.js

But I can’t figure out how to recompile it to test the change. I tried rake assets:precompile but it didn’t seem to do what I wanted.

Can anyone tell me how to test my change please?


(Jason Taylor) #9

Nevermind. A little searching and I found ./launcher restart app did the trick.


(Jason Taylor) #10

The fix works, here is the pull request:

https://github.com/discourse/discourse/pull/2540


(system) #11

(Sam Saffron) #12