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

**URL:** https://meta.discourse.org/t/preview-not-working-when-using-object-store-wrong-markdown-it-url/215549
**Category:** Self-hosting
**Created:** [January 21, 2022, 10:02am UTC](https://meta.discourse.org/t/preview-not-working-when-using-object-store-wrong-markdown-it-url/215549 "2022-01-21T10:02:55Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![unteem](https://avatars.discourse-cdn.com/v4/letter/u/d07c76/32.png) [@unteem](https://meta.discourse.org/u/unteem)
#### Post date: [January 21, 2022, 10:02am UTC](https://meta.discourse.org/t/preview-not-working-when-using-object-store-wrong-markdown-it-url/215549/1 "2022-01-21T10:02:55Z")

</div>

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:

```plaintext
  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:

```plaintext
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 🙂

Thanks for your help

---

<div class="post-metadata">

### Author: ![Benjamin\_D](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/benjamin_d/32/277831_2.png) [@Benjamin\_D](https://meta.discourse.org/u/Benjamin_D)
#### Post date: [January 21, 2022, 10:14am UTC](https://meta.discourse.org/t/preview-not-working-when-using-object-store-wrong-markdown-it-url/215549/2 "2022-01-21T10:14:16Z")

</div>

> [@unteem](#):
>
> where this URL is set.

I think it’s there [discourse/app/helpers/application\_helper.rb at 70af45055ae24dc7eb1a20678a52ed3ec69421c3 · discourse/discourse · GitHub](https://github.com/discourse/discourse/blob/70af45055ae24dc7eb1a20678a52ed3ec69421c3/app/helpers/application_helper.rb#L580)

---

<div class="post-metadata">

### Author: ![unteem](https://avatars.discourse-cdn.com/v4/letter/u/d07c76/32.png) [@unteem](https://meta.discourse.org/u/unteem)
#### Post date: [January 21, 2022, 10:45am UTC](https://meta.discourse.org/t/preview-not-working-when-using-object-store-wrong-markdown-it-url/215549/3 "2022-01-21T10:45:19Z")

</div>

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.

```plaintext
<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.

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [January 21, 2022, 5:32pm UTC](https://meta.discourse.org/t/preview-not-working-when-using-object-store-wrong-markdown-it-url/215549/4 "2022-01-21T17:32:24Z")

</div>

> [@unteem](#):
>
> ` DISCOURSE_S3_ENDPOINT: https://hot-objects.liiib.re`  
> ` DISCOURSE_S3_CDN_URL: https://forum-beta-liiib-re.hot-objects.liiib.re`

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?

---

<div class="post-metadata">

### Author: ![unteem](https://avatars.discourse-cdn.com/v4/letter/u/d07c76/32.png) [@unteem](https://meta.discourse.org/u/unteem)
#### Post date: [January 28, 2022, 11:36am UTC](https://meta.discourse.org/t/preview-not-working-when-using-object-store-wrong-markdown-it-url/215549/5 "2022-01-28T11:36:32Z")

</div>

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 !
