# Is it possible to test Discourse Embed comment on localhost?

**URL:** https://meta.discourse.org/t/is-it-possible-to-test-discourse-embed-comment-on-localhost/42724
**Category:** Support
**Created:** [18.Апрель.2016 11:25:48 UTC](https://meta.discourse.org/t/is-it-possible-to-test-discourse-embed-comment-on-localhost/42724 "2016-04-18T11:25:48Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![thangngoc89](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/thangngoc89/32/115436_2.png) [@thangngoc89](https://meta.discourse.org/u/thangngoc89)
#### Post date: [18.Апрель.2016 11:25:48 UTC](https://meta.discourse.org/t/is-it-possible-to-test-discourse-embed-comment-on-localhost/42724/1 "2016-04-18T11:25:48Z")

</div>

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](https://meta.discourse.org/t/embedding-discourse-comments-via-javascript/31963) 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’s `cpp.dev`

- Discourse : Using vagrant with latest commit from Github.

- My website is running at `http://cpp.dev:3000`

- I added both `cpp.dev:3000`and `cpp.dev` to hosts list in Admin \> Customize \> Embedding section

- Website embed code:

```js
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:

```plaintext
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

```plaintext
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/

```plaintext
	
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.

---

<div class="post-metadata">

### Author: ![eviltrout](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eviltrout/32/5275_2.png) [@eviltrout](https://meta.discourse.org/u/eviltrout)
#### Post date: [18.Апрель.2016 15:08:11 UTC](https://meta.discourse.org/t/is-it-possible-to-test-discourse-embed-comment-on-localhost/42724/2 "2016-04-18T15:08:11Z")

</div>

This might be due to vagrant’s port forwarding. Your site believes its host is `:4000` when in fact it’s `:3000`. When I test locally I am not using such port forwarding and it works correctly.

Perhaps try the `force hostname` site setting with `:3000`? That might correct the issue.

---

<div class="post-metadata">

### Author: ![thangngoc89](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/thangngoc89/32/115436_2.png) [@thangngoc89](https://meta.discourse.org/u/thangngoc89)
#### Post date: [18.Апрель.2016 15:39:50 UTC](https://meta.discourse.org/t/is-it-possible-to-test-discourse-embed-comment-on-localhost/42724/3 "2016-04-18T15:39:50Z")

</div>

I’m not too familiar with Vagrant or Ruby ecosystem but can you tell me how to start Discourse in a different port (say 4000) so the port is the same in Vagrant and host machine.

---

<div class="post-metadata">

### Author: ![eviltrout](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eviltrout/32/5275_2.png) [@eviltrout](https://meta.discourse.org/u/eviltrout)
#### Post date: [18.Апрель.2016 15:53:02 UTC](https://meta.discourse.org/t/is-it-possible-to-test-discourse-embed-comment-on-localhost/42724/4 "2016-04-18T15:53:02Z")

</div>

I don’t think you can start it on the same port in both machines but maybe someone can correct me. I run Discourse on “bare metal” but just installing ruby/etc on OSX.

---

<div class="post-metadata">

### Author: ![thangngoc89](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/thangngoc89/32/115436_2.png) [@thangngoc89](https://meta.discourse.org/u/thangngoc89)
#### Post date: [18.Апрель.2016 16:02:17 UTC](https://meta.discourse.org/t/is-it-possible-to-test-discourse-embed-comment-on-localhost/42724/5 "2016-04-18T16:02:17Z")

</div>

> [@eviltrout](#):
>
> I run Discourse on “bare metal” but just installing ruby/etc on OSX.

Yeah. Using Vagrant is a little slow on my old Linux machine. I believe there is a Advanced Development Installation Guide to run Discourse directly on the host machine.

Turn out, using port 3000 on both guest and host machine is quite simple. Just open Vagrantfile and edit the port forwarding section.

I’m testing the original problem and give feedback later

---

<div class="post-metadata">

### Author: ![thangngoc89](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/thangngoc89/32/115436_2.png) [@thangngoc89](https://meta.discourse.org/u/thangngoc89)
#### Post date: [18.Апрель.2016 16:09:23 UTC](https://meta.discourse.org/t/is-it-possible-to-test-discourse-embed-comment-on-localhost/42724/6 "2016-04-18T16:09:23Z")

</div>

New setup :

- Discourse port: 3000 (both guest and host machine)
- My website: 3001

OK. So I set `force hostname` to `localhost:3000`

Same error on browser console

```plaintext
Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('http://localhost:3000') does not match the recipient window's origin ('http://cpp.dev:3001')

```

---

<div class="post-metadata">

### Author: ![thangngoc89](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/thangngoc89/32/115436_2.png) [@thangngoc89](https://meta.discourse.org/u/thangngoc89)
#### Post date: [18.Апрель.2016 18:04:54 UTC](https://meta.discourse.org/t/is-it-possible-to-test-discourse-embed-comment-on-localhost/42724/7 "2016-04-18T18:04:54Z")

</div>

I Installed a Discourse instance on Digital Ocean VPS (with getting started guide) and everything started working again. So to answer the topic’s title: No, it’s not possible.

---

<div class="post-metadata">

### Author: ![eviltrout](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eviltrout/32/5275_2.png) [@eviltrout](https://meta.discourse.org/u/eviltrout)
#### Post date: [18.Апрель.2016 21:36:23 UTC](https://meta.discourse.org/t/is-it-possible-to-test-discourse-embed-comment-on-localhost/42724/8 "2016-04-18T21:36:23Z")

</div>

Clarification: It does work on localhost if you use bare metal, as I’ve done this many times. The issue here is finding a sutiable vagrant configuration to test/develop it.

As for your error, you’ve forced hostname to `localhost:3000` and are visiting it on `http://cpp.dev:3001` – those need to match so I’d force the hostname to be whatever you are access it via your web browser.

---

<div class="post-metadata">

### Author: ![kevincolten](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kevincolten/32/120986_2.png) [@kevincolten](https://meta.discourse.org/u/kevincolten)
#### Post date: [09.Январь.2017 22:12:50 UTC](https://meta.discourse.org/t/is-it-possible-to-test-discourse-embed-comment-on-localhost/42724/9 "2017-01-09T22:12:50Z")

</div>

Can we confirm this still works on a local bare-metal environment (specifically Mac). I’m wanting to work on a solution for embedding comments on a site behind basic http auth, but can’t get comments embedding between two localhost ports for development. I am whitelisting the site correctly, but am getting stuck on the “Loading Discussion…” view. I can get it breaking correctly with a 401 error in production, but when local, the [job](https://github.com/discourse/discourse/blob/master/app/controllers/embed_controller.rb#L50) seems to just up and disappear.

---

<div class="post-metadata">

### Author: ![kevincolten](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kevincolten/32/120986_2.png) [@kevincolten](https://meta.discourse.org/u/kevincolten)
#### Post date: [16.Январь.2017 16:25:01 UTC](https://meta.discourse.org/t/is-it-possible-to-test-discourse-embed-comment-on-localhost/42724/10 "2017-01-16T16:25:01Z")

</div>

Trying to re-animate this discussion in a [brand new topic](https://meta.discourse.org/t/getting-discourse-embed-comments-working-in-development/55851)

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [08.Июнь.2024 12:45:00 UTC](https://meta.discourse.org/t/is-it-possible-to-test-discourse-embed-comment-on-localhost/42724/11 "2024-06-08T12:45:00Z")

</div>

Эта тема была автоматически закрыта через 2973 дня. Новые ответы больше не принимаются.
