I’m testing Discourse Embed comment system for my static blog using React locally but I can’t get it to work. I’m sure that I read the instruction like 10 times. So I’m thinking that localhost should be the blocker here.
Set up :
-
A fake domain
cpp.dev
in/etc/hosts
to for routing to localhost. Let’s say it’scpp.dev
-
Discourse : Using vagrant with latest commit from Github.
- Discourse port inside vagrant: 3000
- Host port for Discourse: 4000. I can access Discourse via
http://cpp.dev:4000
-
My website is running at
http://cpp.dev:3000
-
I added both
cpp.dev:3000
andcpp.dev
to hosts list in Admin > Customize > Embedding section -
Website embed code:
DiscourseEmbed = {
discourseUrl: "http://cpp.dev:4000/",
discourseEmbedUrl: window.location,
}
Looking good, now let’s run it. It shows up an iframe with loading discussion
forever.
- In terminal, I see this message:
I, [2016-04-18T07:24:10.751058 #25645] INFO -- : Processing by EmbedController#comments as HTML
I, [2016-04-18T07:24:10.784677 #25645] INFO -- : Parameters: {"embed_url"=>"http://cpp.dev:3000/dnh-cpp/cpp-co-ban/0-gioi-thieu-tong-quan/0-0-gioi-thieu-ve-khoa-hoc/"}
D, [2016-04-18T07:24:10.807149 #25645] DEBUG -- : User Load (5.1ms) SELECT "users".* FROM "users" WHERE "users"."auth_token" = '951c06ee26073030dc3cf264e80804fa' LIMIT 1 [["auth_token", "951c06ee26073030dc3cf264e80804fa"]]
D, [2016-04-18T07:24:10.866750 #25645] DEBUG -- : (3.6ms) SELECT "topic_embeds"."topic_id" FROM "topic_embeds" WHERE (lower(embed_url) = 'http://cpp.dev:3000/dnh-cpp/cpp-co-ban/0-gioi-thieu-tong-quan/0-0-gioi-thieu-ve-khoa-hoc')
I, [2016-04-18T07:24:10.917468 #25645] INFO -- : Rendered embed/loading.html.erb within layouts/embed (0.9ms)
I, [2016-04-18T07:24:10.987482 #25645] INFO -- : Completed 200 OK in 186ms (Views: 61.0ms | ActiveRecord: 8.7ms)
- In browser console, I see this
Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('http://cpp.dev:4000') does not match the recipient window's origin ('http://cpp.dev:3000').
-
No new topic was created.
-
Some suspicious log as `/logs/
Started GET "/dnh-cpp/cpp-co-ban/0-gioi-thieu-tong-quan/0-0-gioi-thieu-ve-khoa-hoc/" for 127.0.0.1 at 2016-04-18 07:29:25 -0400
6:29 pm
Permalink Exists (1.1ms) SELECT 1 AS one FROM "permalinks" WHERE "permalinks"."url" = 'dnh-cpp/cpp-co-ban/0-gioi-thieu-tong-quan/0-0-gioi-thieu-ve-khoa-hoc' LIMIT 1 [["url", "dnh-cpp/cpp-co-ban/0
6:29 pm
ActionController::RoutingError (No route matches [GET] "/dnh-cpp/cpp-co-ban/0-gioi-thieu-tong-quan/0-0-gioi-thieu-ve-khoa-hoc") /var/lib/gems/2.2.0/gems/actionpack-4.2.6/lib/action_dispatch/middleware
Where is the wrong part in my setup ? Any help would be appriciated.