Where I should go to set the `DISCOURSE_ENABLE_CORS` env variable?

1 Like

I believe you have to set
DISCOURSE_ENABLE_CORS: true
in your app.yml (somewhere in the env section)

2 Likes

Shouldnā€™t it be setting the DISCOURSE_ENABLE_CORS variable for discourse?

1 Like

Iā€™m not sure what you are saying, but please try doing what was recommended. Iā€™m pretty sure that you can just do a ./launcher destroy app;./launcher start app rather than a full rebuild.

3 Likes

Thank you for your reply. Sorry for not being clear enough in my previous message.

Iā€™m using Discourse hosted instance and going to embed Discourse to my website, and when I try to get contentDoument object of the iframe of embedded Discourse, I found the cross origin limit. In admin setting page, I noticed there is the ā€œcors originsā€ setting as shown in the topic picture. Then I add my testing origin url, but not worked. And I noticed the tip that is The DISCOURSE_ENABLE_CORS env variable must be set to true to enable CORS. However, I canā€™t find where to set DISCOURSE_ENABLE_CORS in admin settings.
I want to know how to set DISCOURSE_ENABLE_CORS, or if my cross-domain configuration is not working, is it related to this setting.

1 Like

Embedding is not my forte, but I think you would set that in /admin/customize/embedding rather than changing the environment variable?

4 Likes

Thanks for your reply. I tried it but it didnā€™t work.

1 Like

If you want us to help you need to explain what you tried in detail.

1 Like

This is what I have configured in /admin/customize/embedding, but no use for cross-origin.

I donā€™t think you can do that.

There is a hidden site setting that allows embedding an iframe but I suspect that itā€™s not available on standard or business plans. You can contact your support contact to ask.

Embedding discourse on an iframe is not officially supported.

2 Likes

iframe is created by official js script. Iā€™m using the codes that are provided on /admin/customize/embedding, as blow:


I need to keep the embedded parts consistent with the color pattern of my website, so I have to access the iframe althogh the iframe is not created by me.

@mikeguo what is the platform of the site into which you are trying to embed your Discourse Topics?

For example, is it a Wordpress site, or a Ghost blog?

Please provide an URL to a Post on the destination site.

All I can see is this (from the screenshot of the code in your Topic above):

https://e53c-185-143-220-5.eu.ngrok.io/

So, for example, I used the ā€˜DISCOURSE_ENABLE_CORSā€™ env variable as described in this post to display content from my Discourse forum on a page within my Ghost blogā€¦

However, the feature you seem to be trying to use from your code posted above hereā€¦

ā€¦seems to indicate that you are trying to embed Topics from your Discourse forum AS POSTS within your external site, which is a different use case.

We need you to explain better what it is that you are trying to do hereā€¦

1 Like

Thank you very much for your detailed explanation.
https://algo.monster is my website that I want to embed Discourse in. Specifically speaking,
embed Discourse in article page to display comments, and replace Cusdis Iā€™m using. For example,
the article https://algo.monster/problems/math-basics, and comments:


My website https://algo.monster doesnā€™t use a blogging platform, neither Wordpress nor Ghost. My website is implemented by my own code and deployed on my own cloud server.
Using the codes that are provided on /admin/customize/embedding, embedded Discourse are shown correctly.
The problem I hope to solve by configuring DISCOURSE_ENABLE_CORS is as below:

This url is the one Iā€™m using for testing and should not cause cross-origin issues.

Thank you @mikeguo ā€“ what have you put into your script snippet for the discourseEmbedUrl where it says ā€˜REPLACE_MEā€™ ?

To Link to existing topics than creating topics automatically, I replaced the discourseEmbedUrl param with topicId, as below:

Thanks again @mikeguo ā€“ regrets, but this is now beyond my ability to help any furtherā€¦ I hope someone else here can adviseā€¦

1 Like

Thank you for your help anyway :sparkling_heart:

1 Like