Discourse on subdirectory - doubling relative_url parameter

(Dejan Milosevic) #1

Ok, here what i did:

in production.rb i added:

   config.relative_url_root = "/forum"
   config.action_controller.asset_host = "forum.domain.com"

i configured forum.domain.com in nginx to have root for assets and that is working fine

in domain.com in nginx i configuret proxy pass in location /forum to my ruby server port

everyting is working fine (message bus,assets etc) except 2 things:

When i go to domain.com/forum - discourse loads main page fine but rewrite url to domain.com with javascript - i want it to stay at domain.com/forum

when i try to go latest for example: javascript is trying to get: http://domain.com/forum/forum/latest.json (link with 1 forum works), so it doubles subfolder

same is for categories, topics etc.

How can i fix this?

(Dejan Milosevic) #2

Ok, i fixed first issue, but it seems that second is bug.

So: when you set
config.relative_url_root = “/forum”

in production.rb

some links for json fetching have double relative_url_root parameter

like : http://domain.com/forum/forum/latest.json

Does anybody know how ti fix it?

(Dejan Milosevic) #3

This is javascript part which is doing wrong

Discourse = Ember.Application.createWithMixins(Discourse.Ajax, {
 rootElement: '#main',

  // Whether the app has focus or not
  hasFocus: true,

// Helps with integration tests

 getURL: function(url) {
 // If it's a non relative URL, return it.
if (url.indexOf('http') === 0) return url;

var u = (Discourse.BaseUri === undefined ? "/" : Discourse.BaseUri);
if (u[u.length-1] === '/') {
  u = u.substring(0, u.length-1);
return u + url;

so when discourse tries to do ajax he is doing $.ajax(Discourse.getURL(url)…
and in return u + ulr is /forum + /forum/latest.json

Can i have assistance in this from authors? Thank you very much.

(Dejan Milosevic) #4

This portion of code is in discourse.js in app/assets/javascripts

i opened and added before - return u + url

        if (url.indexOf('u) != 0) return url;

and precompiled assets

and still dont work

(Dejan Milosevic) #5

my mistake, i should put:

     if (url.indexOf('u) != -1) return url;

now everyting working fine, and steps for subdirectory install are:

in production.rb i added:

   config.relative_url_root = "/forum"
   config.action_controller.asset_host = "forum.domain.com"

in jsapp/routes/discourse_location.js set url to ‘/forum’

hack in app/assets/javascripts/discourse.js whic i mentioned above

and thats it! Subdirectory install working like charm!

(eriko) #6

If it does not effect non suburl installs you should clone the repo and make a patch.

(Dejan Milosevic) #7

I think it is better to with this one line fix we have suburl and subdirectory install working. it seems there is bad logic for using this function getURL, and for some api routes it triggers multiple times, and then add prefix multiple times. This one line of code is just checking if prefix is already added and dont add prefix in that case. Authors merged request, i am glad i contributed to this awesome project!

(Jeff Atwood) #8

This topic was automatically closed after 1 day. New replies are no longer allowed.