CORS origins setup does not work

I want to embed the latest updates from our community on my website:

To accomplish this, I am trying to access the latest.json and will parse that appropriately and embed on my site:

I went to admin and setup the CORS origins:

I even updated app.yml with the following lines and rebuild the whole thing:
DISCOURSE_ENABLE_CORS: true
DISCOURSE_CORS_ORIGIN: ‘https://www.schulminator.com/
I don’t know if this is needed but it does work with this setting or without.

But still same issue as you check on this site:

Access to XMLHttpRequest at ‘https://community.schulminator.com/latest.json’ from origin ‘https://www.schulminator.com’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.

I am really stuck here…

3 Likes

Same problem here
Has someone been able to get it work?

3 Likes

If anyone has a similar problem with a CORS configuration, please check that you removed the trailing slash from your link. A stupid mistake that cost me a couple of hours of my time. :sweat_smile:

5 Likes

I think the CORS setting tip should definitely be made clearer:

Current Text

Allowed origins for cross-origin requests (CORS). Each origin must include http:// or https://. The DISCOURSE_ENABLE_CORS env variable must be set to true to enable CORS.

Draft Proposition

Allowed origins for cross-origin requests (CORS). Each origin must include http:// or https:// and no trailing slash. The DISCOURSE_ENABLE_CORS env variable must be set to true to enable CORS.

Btw, how would one make a PR for something like this? Should it change only the English locale here and the translations will be managed elsewhere (e.g. through Transifex), or should the translations be also covered by the PR?

2 Likes

If the trailing slash is a problem, our code should auto-remove it @sam.

6 Likes

@vinothkannans can you change it so we auto strip trailing slash here?

3 Likes

This is now fixed in the PR below

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

4 Likes