Preview not working when using object store - wrong markdown-it url

When configuring Object Store, preview for topics/posts are not working.

Discourse is configured with an Object Store
Install is on docker, following the doc.
Discourse version: 2.8.0.beta11

Here are my env variables for S3 configs:

  DISCOURSE_CDN_URL: https://discourse.liiib.re
  DISCOURSE_USE_S3: true
  DISCOURSE_S3_REGION: default
  DISCOURSE_S3_ENDPOINT: https://hot-objects.liiib.re 
  DISCOURSE_S3_ACCESS_KEY_ID: ACCESS_KEY_ID
  DISCOURSE_S3_SECRET_ACCESS_KEY: SUPER_SECRET_KEY
  DISCOURSE_S3_CDN_URL: https://forum-beta-liiib-re.hot-objects.liiib.re
  DISCOURSE_S3_BUCKET: forum-beta-liiib-re
  DISCOURSE_S3_INSTALL_CORS_RULE: false

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.

If someone can point me to the right direction :slight_smile:

Thanks for your help

2 Likes

I think it’s there discourse/application_helper.rb at 70af45055ae24dc7eb1a20678a52ed3ec69421c3 · discourse/discourse · GitHub

That was my guess also, forgot to mention that.

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.

<meta id="data-discourse-setup" data-cdn="https://discourse.liiib.re" data-base-url="https://discourse.liiib.re" data-base-uri="" data-environment="production" data-letter-avatar-version="5_c12935382690395be92856801563c2b7" data-markdown-it-url="https://forum-beta-liiib-re.hot-objects.liiib.re/assets/markdown-it-bundle-9d939740bdeca330e5984bed41d12eab63736c1f720ab68e0c2a2d672c01adc2.br.js" data-service-worker-url="service-worker.js" data-default-locale="en" data-asset-version="be5bda1657984e9e27d7d3c27ab24add" data-disable-custom-css="false" data-highlight-js-path="/highlight-js/discourse.liiib.re/084d101d62e4ceb91462fa1464b341511141973f.js" data-svg-sprite-path="/svg-sprite/discourse.liiib.re/svg-1-c105fc3106297bc864bbadbd418cf380c71e3a4b.js" data-enable-js-error-reporting="true" data-color-scheme-is-dark="false" data-user-color-scheme-id="4" data-user-dark-scheme-id="1" data-s3-cdn="https://forum-beta-liiib-re.hot-objects.liiib.re" data-s3-base-url="//forum-beta-liiib-re.hot-objects.liiib.re">

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.

2 Likes

I don’t think it’s going to work with S3 CDN URL is a subdomail of S3 endpoint. Can you try using distinct same level subdomains for both?

2 Likes

Ok back on it. Looks like you are right.

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 !

1 Like