In a Discourse installation using an object store (S3-compatible setup), user unteem reported that post/topic previews fail due to an incorrect URL being generated for markdown-it-bundle.js. The browser attempts to load https:https://..., causing a 404, because DISCOURSE_S3_CDN_URL is being incorrectly prefixed with https:. While the HTML meta tag correctly references the asset URL, the JavaScript dynamically injects the malformed script tag. Benjamin_D suggested checking application_helper.rb, but unteem confirmed the issue lies in JS logic, not Ruby. Falco hypothesized that using a CDN URL as a subdomain of the S3 endpoint might be the root cause. Following this, unteem confirmed switching DISCOURSE_S3_CDN_URL to a subpath (e.g., https://hot-objects.liiib.re/forum-beta-liiib-re) resolved the issue. They noted this setup is common in self-hosted environments without external CDNs and questioned whether Discourse should support subdomain-based CDN URLs for S3. The workaround works, but the underlying behavior may warrant a code fix or documentation update.
When I check the browser inspector, URL for markdown-it-bundle is pointing to https:https://forum-beta-liiib-re.hot-objects.liiib.re/assets/markdown-it-bundle-9d939740bdeca330e5984bed41d12eab63736c1f720ab68e0c2a2d672c01adc2.br.js
It should not prefix the DISCOURSE_S3_CDN_URL with https: as its already there.
In the console I have the following error:
Loading failed for the <script> with source “https://discourse.liiib.re/https://forum-beta-liiib-re.hot-objects.liiib.re/assets/markdown-it-bundle-9d939740bdeca330e5984bed41d12eab63736c1f720ab68e0c2a2d672c01adc2.br.js”.
I guess my browser is redirecting the https:https://... URL to this one.
I have been trying to find, unsuccessfully, where this URL is set.
Well I’m not 100% sure as I don’t really have proper dev environment to test everything thoroughly, but it does not seem to come from there.
From what I saw, script_asset_path('markdown-it-bundle') is returning the right URL. And i think its used to build this meta HTML tag which looks fine.
It seems to be the js that is putting the wrong url with the https: prefix. I could not find where its coming from though.
Its only when I open the editor that I have a <script src="https:https://forum-beta-liiib-re.hot-objects.liiib.re/assets/markdown-it-bundle-9d939740bdeca330e5984bed41d12eab63736c1f720ab68e0c2a2d672c01adc2.br.js"</script> popping up.
So I tried to set DISCOURSE_S3_CDN_URL as a bucket subpath https://hot-objects.liiib.re/forum-beta-liiib-re and it is now working.
Do you think it would be reasonable to allow S3 CDN as a subdomain of S3 endpoint ?
In my case, which could be similar to other self-hosted setups, I’m not using an external CDN (nginx on top of minio can be considered as the CDN) so I don’t need to set it on another domain.
I actually setup the subdomain bucket because, I think, its required for discourse to manage uploads
Anyways it solved it and its working for me. Thanks for the help !