# Self Link previews not showing for private sites?

**URL:** https://meta.discourse.org/t/self-link-previews-not-showing-for-private-sites/35591
**Category:** Bug
**Created:** [November 16, 2015, 12:23am UTC](https://meta.discourse.org/t/self-link-previews-not-showing-for-private-sites/35591 "2015-11-16T00:23:25Z")
**Posts on this page:** 16
**Page:** 1

<div class="post-metadata">

### Author: ![Joey\_Tuan](https://avatars.discourse-cdn.com/v4/letter/j/db5fbb/32.png) [@Joey\_Tuan](https://meta.discourse.org/u/Joey_Tuan)
#### Post date: [November 16, 2015, 12:23am UTC](https://meta.discourse.org/t/self-link-previews-not-showing-for-private-sites/35591/1 "2015-11-16T00:23:25Z")

</div>

My link preview is just showing the URL and no link preview. Note: my website is a private instance. Any suggestions to get this working?

 ![](https://global.discourse-cdn.com/meta/original/3X/d/7/d76f8316b56a7a3d0ca68d12593489170b4509aa.png)

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [November 16, 2015, 3:23am UTC](https://meta.discourse.org/t/self-link-previews-not-showing-for-private-sites/35591/2 "2015-11-16T03:23:29Z")

</div>

Private urls behind login cannot onebox.

---

<div class="post-metadata">

### Author: ![Joey\_Tuan](https://avatars.discourse-cdn.com/v4/letter/j/db5fbb/32.png) [@Joey\_Tuan](https://meta.discourse.org/u/Joey_Tuan)
#### Post date: [November 16, 2015, 4:10am UTC](https://meta.discourse.org/t/self-link-previews-not-showing-for-private-sites/35591/3 "2015-11-16T04:10:07Z")

</div>

Is it possible to turn it off completely then, so I can show the full link?

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [November 16, 2015, 4:54am UTC](https://meta.discourse.org/t/self-link-previews-not-showing-for-private-sites/35591/4 "2015-11-16T04:54:49Z")

</div>

Does it actually render like that if you post it though?

---

<div class="post-metadata">

### Author: ![Joey\_Tuan](https://avatars.discourse-cdn.com/v4/letter/j/db5fbb/32.png) [@Joey\_Tuan](https://meta.discourse.org/u/Joey_Tuan)
#### Post date: [November 16, 2015, 5:09am UTC](https://meta.discourse.org/t/self-link-previews-not-showing-for-private-sites/35591/5 "2015-11-16T05:09:03Z")

</div>

Yup it renders exactly like that.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [November 16, 2015, 6:03am UTC](https://meta.discourse.org/t/self-link-previews-not-showing-for-private-sites/35591/6 "2015-11-16T06:03:22Z")

</div>

Can you repro this @techapj? We should not render a busted onebox when a password protected site oneboxes itself.

---

<div class="post-metadata">

### Author: ![techAPJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/techapj/32/342990_2.png) [@techAPJ](https://meta.discourse.org/u/techAPJ)
#### Post date: [November 16, 2015, 5:38pm UTC](https://meta.discourse.org/t/self-link-previews-not-showing-for-private-sites/35591/7 "2015-11-16T17:38:42Z")

</div>

> [@codinghorror](#):
>
> Can you repro this @techapj?

Yes I can repro this, but only on private (login required) _hosted_ instances.

The correct oneboxing behaviour in case of private instances is that the post gets oneboxed using [local onebox class](https://github.com/discourse/discourse/blob/master/lib/onebox/engine/discourse_local_onebox.rb), but in case of private hosted instances this is not happening (it’s using [WhitelistedGenericOnebox](https://github.com/discourse/onebox/blob/master/lib/onebox/engine/whitelisted_generic_onebox.rb) class instead).

I am looking into this issue and will post here with more updates.

---

<div class="post-metadata">

### Author: ![michael2](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/michael2/32/115199_2.png) [@michael2](https://meta.discourse.org/u/michael2)
#### Post date: [November 19, 2015, 1:09am UTC](https://meta.discourse.org/t/self-link-previews-not-showing-for-private-sites/35591/8 "2015-11-19T01:09:05Z")

</div>

This issue is also affecting me. We are running the latest Discourse, using the standard Docker container on a Digital Ocean Ubuntu droplet.

---

<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 18, 2016, 8:19pm UTC](https://meta.discourse.org/t/self-link-previews-not-showing-for-private-sites/35591/9 "2016-01-18T20:19:38Z")

</div>

I have a login required and I’m seeing this too.

If your queue is too long could you give me any directions to craft a PR?

---

<div class="post-metadata">

### Author: ![techAPJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/techapj/32/342990_2.png) [@techAPJ](https://meta.discourse.org/u/techAPJ)
#### Post date: [January 25, 2016, 8:29am UTC](https://meta.discourse.org/t/self-link-previews-not-showing-for-private-sites/35591/10 "2016-01-25T08:29:49Z")

</div>

Thanks Rafael!

The underlying issue is that in case of _some_ Discourse instances (private hosted in my experience) the DiscourseLocalOnebox engine is not being used (which is responsible for oneboxing internal topics/posts)

[https://github.com/discourse/discourse/blob/master/lib/onebox/engine/discourse\_local\_onebox.rb#L6](https://github.com/discourse/discourse/blob/master/lib/onebox/engine/discourse_local_onebox.rb#L6)

I can’t figure out why in some cases the above engine is not being used, will appreciate your help with this.

---

<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: [February 1, 2016, 2:20pm UTC](https://meta.discourse.org/t/self-link-previews-not-showing-for-private-sites/35591/11 "2016-02-01T14:20:52Z")

</div>

Hey @techAPJ, good and bad news!

First, the good news: It’s working on my instance.

Second: Looks like the rails method `recognize_path` doesn’t play along with rails `config.relative_url_root`. So my bug wasn’t related with being private at all. Maybe this is @Joey_Tuan case?

So, it’s a subfolder 🐛 after all 😄 (I stump on subfolder bugs even when I’m looking somewhere else).

If we want to fix it at Discourse level we need:

```diff
diff --git a/lib/onebox/engine/discourse_local_onebox.rb b/lib/onebox/engine/discourse_local_onebox.rb
index 5fd4897..5e3b797 100644
--- a/lib/onebox/engine/discourse_local_onebox.rb
+++ b/lib/onebox/engine/discourse_local_onebox.rb
@@ -14,7 +14,7 @@ module Onebox
         if other.kind_of?(URI)
           uri = other
           begin
- route = Rails.application.routes.recognize_path(uri.path)
+ route = Rails.application.routes.recognize_path(uri.path.sub(Discourse.base_uri, ""))
             case route[:controller]
             when 'uploads'
               super
@@ -34,7 +34,7 @@ module Onebox
 
       def to_html
         uri = URI::parse(@url)
- route = Rails.application.routes.recognize_path(uri.path)
+ route = Rails.application.routes.recognize_path(uri.path.sub(Discourse.base_uri, ""))
         url = @url.sub(/[&?]source_topic_id=(\d+)/, "")
         source_topic_id = $1.to_i

```

And we have local oneboxing at subfolder install working.

---

<div class="post-metadata">

### Author: ![techAPJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/techapj/32/342990_2.png) [@techAPJ](https://meta.discourse.org/u/techAPJ)
#### Post date: [February 1, 2016, 3:19pm UTC](https://meta.discourse.org/t/self-link-previews-not-showing-for-private-sites/35591/12 "2016-02-01T15:19:10Z")

</div>

Thanks Rafael! Awesome work 👍

Can you send a PR with your fix? I’ll deploy and verify on private hosted Discourse instances.

---

<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: [February 1, 2016, 3:31pm UTC](https://meta.discourse.org/t/self-link-previews-not-showing-for-private-sites/35591/13 "2016-02-01T15:31:41Z")

</div>

[https://github.com/discourse/discourse/pull/3991](https://github.com/discourse/discourse/pull/3991)

PS.: Should this be fixed upstream on rails?

---

<div class="post-metadata">

### Author: ![techAPJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/techapj/32/342990_2.png) [@techAPJ](https://meta.discourse.org/u/techAPJ)
#### Post date: [February 6, 2016, 3:37pm UTC](https://meta.discourse.org/t/self-link-previews-not-showing-for-private-sites/35591/14 "2016-02-06T15:37:19Z")

</div>

Just checked, this issue can still be reproduced on private (login required) hosted instances. 😞

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [November 3, 2016, 9:54pm UTC](https://meta.discourse.org/t/self-link-previews-not-showing-for-private-sites/35591/15 "2016-11-03T21:54:04Z")

</div>

Should be fixed now 🍌

[https://github.com/discourse/discourse/commit/a655e4b09259fa5a908416b0add303d7c710ac1f](https://github.com/discourse/discourse/commit/a655e4b09259fa5a908416b0add303d7c710ac1f)

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [November 4, 2016, 10:00pm UTC](https://meta.discourse.org/t/self-link-previews-not-showing-for-private-sites/35591/16 "2016-11-04T22:00:50Z")

</div>

This topic was automatically closed after 24 hours. New replies are no longer allowed.
