# Multiple cors origins on hosted discourse?

**URL:** https://meta.discourse.org/t/multiple-cors-origins-on-hosted-discourse/68172
**Category:** Support
**Created:** [8월 16, 2017, 6:26오후 UTC](https://meta.discourse.org/t/multiple-cors-origins-on-hosted-discourse/68172 "2017-08-16T18:26:59Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![kvz](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kvz/32/120663_2.png) [@kvz](https://meta.discourse.org/u/kvz)
#### Post date: [8월 16, 2017, 6:27오후 UTC](https://meta.discourse.org/t/multiple-cors-origins-on-hosted-discourse/68172/1 "2017-08-16T18:27:05Z")

</div>

Hi, hope I’m asking at the right place! We want to use a hosted (as in paid) discourse account and embed it on three sites to power their comment sections.

It is my understanding that I would need to whitelist 3 domains as cors origins which I’ve done like so: [https://dl.dropboxusercontent.com/s/4zrqarqjln7qj8k/2017-08-16%20at%2020.16.png](https://dl.dropboxusercontent.com/s/4zrqarqjln7qj8k/2017-08-16%20at%2020.16.png)

It seems however upon some testing that only the first domain is returned: [https://dl.dropboxusercontent.com/s/jctq7uejd8lbqbj/2017-08-16%20at%2020.22.png](https://dl.dropboxusercontent.com/s/jctq7uejd8lbqbj/2017-08-16%20at%2020.22.png)

It is my understanding that it’s not possible to return multiple origins in the cors header. In our company we’ve worked around that by checking the `origin`, and matching it against a short whitelist. If it occurs, we return that specific origin for the current request. That way multiple origins can indeed be supported.

Could this be something you’d be willing to support/implement or should we go for a self-hosted solution and hack around this? For one thing, I think the way the interface is now, you would expect it allows multiple origins.

Would be awesome if you’d consider this, as I’m looking forward very much to building a community for our open source projects with discourse! \<3

---

<div class="post-metadata">

### Author: ![neil](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/neil/32/102150_2.png) [@neil](https://meta.discourse.org/u/neil)
#### Post date: [8월 16, 2017, 8:18오후 UTC](https://meta.discourse.org/t/multiple-cors-origins-on-hosted-discourse/68172/2 "2017-08-16T20:18:58Z")

</div>

If the origin of the request matches one of the listed origins, then we return that as the allowed CORS origin.

> <https://github.com/discourse/discourse/blob/main/config/initializers/008-rack-cors.rb#L27-L29>

So it should already be working for you.

---

<div class="post-metadata">

### Author: ![kvz](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kvz/32/120663_2.png) [@kvz](https://meta.discourse.org/u/kvz)
#### Post date: [8월 17, 2017, 2:47오후 UTC](https://meta.discourse.org/t/multiple-cors-origins-on-hosted-discourse/68172/3 "2017-08-17T14:47:52Z")

</div>

Okay then it must be something fishy on my end. I’ll dive deeper, thanks a lot for verifying this for me!

---

<div class="post-metadata">

### Author: ![kvz](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kvz/32/120663_2.png) [@kvz](https://meta.discourse.org/u/kvz)
#### Post date: [8월 17, 2017, 3:09오후 UTC](https://meta.discourse.org/t/multiple-cors-origins-on-hosted-discourse/68172/4 "2017-08-17T15:09:05Z")

</div>

So, as far as I can tell, all requests are coming through correctly. Here are the ones from [discourse.org](http://discourse.org):

 ![](https://global.discourse-cdn.com/meta/original/3X/e/5/e521d5f0f9feee87404f9f7622cd0d611d3b4cee.png)

And these are from our [https://community.transloadit.com](https://community.transloadit.com) server:

 ![](https://global.discourse-cdn.com/meta/original/3X/b/8/b863b8bd36d91073f8ac2e8f7bf83ab2d08d17be.png)

There are no errors in the console (that relate to discourse, or would stop javascript execution):

 ![](https://global.discourse-cdn.com/meta/original/3X/d/e/deacffb2c3cef2377c90b420d8b4dd80ee386ec0.png)

Yet I keep seeing that “Error Embedding” message when testing locally. From the server side, I have configured these four allowed embedding hosts:

 ![](https://global.discourse-cdn.com/meta/original/3X/9/8/98bc4719870ca64b5820a2718f483f5ca7ba4f45.png)

.. as well as enabled these CORS origins:

 ![](https://global.discourse-cdn.com/meta/original/3X/3/6/36868a242511983cc87c77f0c4da39ef5e92d0e2.png)

which according to [these instructions](https://meta.discourse.org/t/embedding-discourse-comments-via-javascript/31963) are the common things that go wrong.

I’m sure I’m doing something silly but since there’s no error I’m unsure how to debug this further. Would you have clues?

---

<div class="post-metadata">

### Author: ![kvz](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kvz/32/120663_2.png) [@kvz](https://meta.discourse.org/u/kvz)
#### Post date: [8월 17, 2017, 6:57오후 UTC](https://meta.discourse.org/t/multiple-cors-origins-on-hosted-discourse/68172/5 "2017-08-17T18:57:52Z")

</div>

Just deployed it to production so you can have a look: [Releasing our official Python SDK | Transloadit](https://transloadit.com/blog/2017/08/python-sdk-release/)

Getting these errors:

`Refused to display 'https://community.transloadit.com/' in a frame because it set 'X-Frame-Options' to 'sameorigin'.`

(which I believe is set on your end and should really allow us to iframe, correct?)

and:

```plaintext
VM2928 comments?embed_url=https%3A%2F%2Ftransloadit.com%2Fblog%2F2017%2F08%2Fpython-sdk-release%2F:17 Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('https://community.transloadit.com') does not match the recipient window's origin ('https://transloadit.com').
postUp @ VM2928 comments?embed_url=https%3A%2F%2Ftransloadit.com%2Fblog%2F2017%2F08%2Fpython-sdk-release%2F:17
window.onload @ VM2928 comments?embed_url=https%3A%2F%2Ftransloadit.com%2Fblog%2F2017%2F08%2Fpython-sdk-release%2F:38

```

Which just confuses me a great deal 🙂

You _can_ see topics are being created now: [https://community.transloadit.com/t/major-improvements-to-our-go-sdk/276](https://community.transloadit.com/t/major-improvements-to-our-go-sdk/276)

But the iframing does not work. Could this be because we enabled HTTPS and your HTTPS terminator sets some additional security enhancing headers that are not compatible with embedding?

---

<div class="post-metadata">

### Author: ![supermathie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/supermathie/32/507518_2.png) [@supermathie](https://meta.discourse.org/u/supermathie)
#### Post date: [8월 17, 2017, 10:36오후 UTC](https://meta.discourse.org/t/multiple-cors-origins-on-hosted-discourse/68172/7 "2017-08-17T22:36:31Z")

</div>

Hi, just wanted to let you know we’re taking a look at this.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [8월 18, 2017, 8:15오후 UTC](https://meta.discourse.org/t/multiple-cors-origins-on-hosted-discourse/68172/11 "2017-08-18T20:15:42Z")

</div>

@sam thinks we have fixed this, and have deployed, can you try again and let us know?

---

<div class="post-metadata">

### Author: ![kvz](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kvz/32/120663_2.png) [@kvz](https://meta.discourse.org/u/kvz)
#### Post date: [8월 19, 2017, 8:18오전 UTC](https://meta.discourse.org/t/multiple-cors-origins-on-hosted-discourse/68172/12 "2017-08-19T08:18:39Z")

</div>

Just tested and it works like a charm! Thanks for the fix, and thanks for a great product!

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [8월 21, 2017, 12:49오후 UTC](https://meta.discourse.org/t/multiple-cors-origins-on-hosted-discourse/68172/13 "2017-08-21T12:49:45Z")

</div>

Note, the error was actually nothing to do with the CORS origins, instead it was a particular HTML structure our “except parser” exploded on. If you had empty content in certain nodes we were totally unable to generate excerpts, something that broke topic creation.

---

<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: [6월 8, 2024, 12:44오후 UTC](https://meta.discourse.org/t/multiple-cors-origins-on-hosted-discourse/68172/14 "2024-06-08T12:44:23Z")

</div>

이 주제는 2487일 후 자동으로 닫혔습니다. 더 이상 답변을 게시할 수 없습니다.
