Linking to the same domain without Ember taking over


(Brit Gardner) #1

I’ve set up a discourse system on my own domain, let’s say http://example.com. The same domain also hosts some static pages, e.g. “about.html”.

When I link to “http://example.com/about.html” from within discourse, I believe ember is capturing the click and nothing is happening. Is there something I must do to enable this “external” link to the same domain discourse is hosted on? Is this possibly intended behaviour?


(Jeff Atwood) #2

Any tips here @eviltrout?

I know we ran into this as well.


(Robin Ward) #3

The problem here is we try to intercept clicks and pass them through our Ember application’s router. When it can’t find a resource, it shows a custom 404 page.

Having said that, we could conceivably turn off that behaviour for sites that want to host static content via a site setting. Or perhaps we could do some magic and perform an AJAX request to see if the resource exists before showing the 404 page.


(Jeff Widman) #4

Does this happen when Discourse is sitting within a subfolder?

We’ve got a lot of linkjuice pointed at Rock Climbing Forums: Main Index so as I think about migration path, I’ve been been planning to just have discourse “own” the /forum subfolder and any links within that.

But we’d have a bunch of static html at the root + other apps on Grades, Topos, Areas & Locations | Rock Climbing Routes | Rockclimbing.com, /gear, etc.

EDIT: Thinking this through more, if I just place an Nginx server in front of Discourse, it can capture all static-file requests so that Discourse/Ember won’t even see them… That should take care of this.


(Jeff Atwood) #5

subfolder deployment is not really supported in Discourse – we almost never test that way, and have zero customers deployed that way, so you’re likely to run into a lot of bugs.

discourse.example.com is the only supported format.


(Jeff Widman) #6

Yes, I’m well aware of that. I understand the reasons why the Discourse team plans to only support Docker-based installs on subdomains, and I think it’s the right choice for the majority of users and for minimizing the amount of time the team spends on support questions.

My question was for anyone else who might be experimenting with this unsupported configuration. Unless the bugs we hit are really severe (I haven’t actually tried it yet), for my site I’ll probably go the subfolder route rather than subdomain for SEO reasons and continuity with existing site structure. Probably just use an Nginx proxy in front of Discourse to handle routing…


(Rafael dos Santos Silva) #7

Sorry for the bump but I’m running into this issue :sadpanda:

I’m running on a subfolder (/forum) and discourse is intercepting links to other apps, like example.com/reports, and sending people to example.com/forum/reports.

Any points where can I hack a workaround this? I’m about to deploy Discourse :cry:


(Jeff Atwood) #8

Sounds like the forward proxy is not configured correctly? Why would it touch example.com/reports when the site root is example.com/forum ?


(Rafael dos Santos Silva) #9

I believe the problem is the parameter redirect=false on click tracker. I’ll try to debug it here.


(Rafael dos Santos Silva) #10

See this:

Forum: example.com/forum
Link: example.com/reports/index.html

url = example.com/reports/index.html
this.origin = example.com

Returns true

We need to test for the sub-folder on subfolders installations.

Edit:

Changing this.origin inside isInternal() to Discourse.BaseUrl + Discourse.BaseUri can work. Let’s try.

Edit: Holy fuck it works!!! I’ll submit a patch!

Edit: Fix same domains links on subfolder installs by xfalcox · Pull Request #3701 · discourse/discourse · GitHub


Subfolder support with Docker
(Rafael dos Santos Silva) #11

This is the last bug on subfolders installs that makes me use a Discourse fork. Can this get merged before 1.4 release? :wink: pretty please


(Robin Ward) #12

@neil just merged this in :smile:


(Rafael dos Santos Silva) #13

Running vanilla Discourse and being able to update without fear


(Neil Lalonde) #14

Feels good to have help with our subfolder support. Thank YOU sir!


(Andy Rothfusz) #15

I’m running into this too. I’m running a standard Discourse (e.g. partners.example.com) and I’m also hosting other services on the same subdomain that I need to link to (e.g. partners.example.com/api-docs) from the forum.

I can maybe go in and hack a specific exclusion in Ember, but that will probably break updates. Did anyone find a way to configure Discourse for linking to local subdirectories when Discourse itself is not in a subdirectory?


(Rafael dos Santos Silva) #16

Today, Discourse.URL.isInternal is a global, and you can rewrite so it return false to /api-docs.

Discourse.URL.isInternal = function(url) {
    if (url && url.length) { 
      if (url.match('meta.discourse.org/api-docs')) { return false; } // NEW LINE
      if (url.indexOf('#') === 0) { return true; }
      if (url.indexOf('/') === 0) { return true; }
      if (url.indexOf(this.origin()) === 0) { return true; }
      if (url.replace(/^http/, 'https').indexOf(this.origin()) === 0) { return true; }
      if (url.replace(/^https/, 'http').indexOf(this.origin()) === 0) { return true; }
    }
    return false;
  };

However, when the Constants Apocalipse comes you will be out of luck :sadpanda:

Maybe, until then, you can migrate to a more standard url scheme?

I don’t usually go with a subfolder inside an app I don’t fully control proxing to another app, with my luck they will always create a route that conflicts in the next version :laughing:.


(Andy Rothfusz) #17

Thanks for the code snippet!

I don’t usually go with a subfolder inside an app I don’t fully control proxing to another app, with my luck they will always create a route that conflicts in the next version

Good points, but I don’t want Discourse to proxy to /api-docs. I have an Nginx above Discourse to handle that. Just let the browser make the request. If I cut and paste “https://partners.example.com/api-docs” into the browser, I get to the api-docs. If I click on the link from within Discourse though, I get the Discourse 404 page, which is really unexpected to me.

I tried installing Discourse within a subfolder (partners.example.com/forum) but that broke in a bunch of different ways and so I gave up and moved it the root.


(Rafael dos Santos Silva) #18

When did you try that? Discourse had some bugs on sub folders but everything is sorted right now.

I’m running 1.4 on subfolder on a fairly busy instance.


(Andy Rothfusz) #19

I tried the subfolder setup on October 16-23.