Redirect back to configurable URL path?

137 views
Skip to first unread message

Steve Hajducko

unread,
Jun 3, 2009, 1:06:47 PM6/3/09
to Gitorious
We installed gitorious on a system where we have several other rails
apps running and I've got it running in a mongrel+apache setup with
mod_proxy.

The problem we're running into is that we run the app as http://host.example.com/git/
- We've found is that there are certain times when gitorious redirects
the user back to /, which ends up being some other site rather than
the app.

I've gone through the code and found a few instances where this
happens - mostly in session_controller, users_controller and
merge_requests_controller. Would it be possible to change this to be
a configurable value via gitorious.yml? I didn't want to post a patch
because I'm not sure if there are other instances yet where gitorious
assumes that it's running out of '/' on the site - I only really did
this to the obvious instances and then added a 'gitorious_url' to the
gitorious.yml file.

If those really are the *only* places, I can submit the patches up -
wasn't sure on the name of the config variable either but I couldn't
think of anything better to call it. :) Maybe gitorious_urlroot

ie -

diff --git a/app/controllers/users_controller.rb b/app/controllers/
users_controller.rb
index 329928b..bed3092 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -88,7 +88,7 @@ class UsersController < ApplicationController
else
flash[:error] = I18n.t "users_controller.activate_error"
end
- redirect_back_or_default('/')
+ redirect_back_or_default(GitoriousConfig['gitorious_url'])
end

def forgot_password
@@ -182,7 +182,7 @@ class UsersController < ApplicationController
session.delete(k)
end
self.current_user = @user
- redirect_back_or_default '/'
+ redirect_back_or_default(GitoriousConfig['gitorious_url'])
else
render :action => 'openid_build'
end

Per Christian B. Viken

unread,
Jun 3, 2009, 1:14:15 PM6/3/09
to gito...@googlegroups.com

On Jun 3, 2009, at 7:06 PM, Steve Hajducko wrote:

>
> We installed gitorious on a system where we have several other rails
> apps running and I've got it running in a mongrel+apache setup with
> mod_proxy.
>
> The problem we're running into is that we run the app as http://host.example.com/git/
> - We've found is that there are certain times when gitorious redirects
> the user back to /, which ends up being some other site rather than
> the app.
>
> I've gone through the code and found a few instances where this
> happens - mostly in session_controller, users_controller and
> merge_requests_controller. Would it be possible to change this to be
> a configurable value via gitorious.yml? I didn't want to post a patch
> because I'm not sure if there are other instances yet where gitorious
> assumes that it's running out of '/' on the site - I only really did
> this to the obvious instances and then added a 'gitorious_url' to the
> gitorious.yml file.
>
> If those really are the *only* places, I can submit the patches up -
> wasn't sure on the name of the config variable either but I couldn't
> think of anything better to call it. :) Maybe gitorious_urlroot

One problem is that the CSS-files contains tons of references to
images found in "/images". Not sure what the best way to deal with
those are, but I'm sure it could be done.

There was a fork of Gitorious that did something similar, I can't
remember the exact name right now. That was for the old version of
Gitorious however, and might not work very well anymore. But maybe you
could get some ideas.

Thomas

unread,
Jun 3, 2009, 1:31:05 PM6/3/09
to Gitorious
The fork still exists as a merge request [1].

We have gitorious running on our private server using a sub base uri
(e.g. http://someserver.com/gitorious/), but we hardcoded almost every
existance of '/' to '/gitorious/'. I have a clone of the new
gitorious, which runs with these modifications. See [2] for more the
changes made to mainline.

Greets, Thomas

[1]: http://gitorious.org/~dcrec1/gitorious/dcrec1s-clone/commit/c37d420f8ccb13933093dcc00af2ce2a4555fc35
[2]: http://gitorious.org/~tschamm/gitorious/tschamms-clone

On Jun 3, 7:14 pm, "Per Christian B. Viken" <per...@northblue.org>
wrote:
> On Jun 3, 2009, at 7:06 PM, Steve Hajducko wrote:
>
>
>
>
>
>
>
> > We installed gitorious on a system where we have several other rails
> > apps running and I've got it running in a mongrel+apache setup with
> > mod_proxy.
>
> > The problem we're running into is that we run the app ashttp://host.example.com/git/

Steve Hajducko

unread,
Jun 3, 2009, 1:44:07 PM6/3/09
to Gitorious
Yeah - just ran into the CSS problem. :/ Considering just running
this out of a vhost rather than a subdir - although it'd be
interesting to see how much work would really be needed to make this
happen.

On Jun 3, 10:31 am, Thomas <tho...@tschamm.de> wrote:
> The fork still exists as a merge request [1].
>
> We have gitorious running on our private server using a sub base uri
> (e.g.http://someserver.com/gitorious/), but we hardcoded almost every
> existance of '/' to '/gitorious/'. I have a clone of the new
> gitorious, which runs with these modifications. See [2] for more the
> changes made to mainline.
>
> Greets, Thomas
>
> [1]:http://gitorious.org/~dcrec1/gitorious/dcrec1s-clone/commit/c37d420f8...

Johan Sørensen

unread,
Jun 4, 2009, 4:16:35 AM6/4/09
to gito...@googlegroups.com
Hi

On Wed, Jun 3, 2009 at 7:44 PM, Steve Hajducko <hajd...@gmail.com> wrote:
>
> Yeah - just ran into the CSS problem. :/  Considering just running
> this out of a vhost rather than a subdir - although it'd be
> interesting to see how much work would really be needed to make this
> happen.
>
> On Jun 3, 10:31 am, Thomas <tho...@tschamm.de> wrote:
>> The fork still exists as a merge request [1].
>>
>> We have gitorious running on our private server using a sub base uri
>> (e.g.http://someserver.com/gitorious/), but we hardcoded almost every
>> existance of '/' to '/gitorious/'. I have a clone of the new
>> gitorious, which runs with these modifications. See [2] for more the
>> changes made to mainline.
>>
>> Greets, Thomas
>>
>> [1]:http://gitorious.org/~dcrec1/gitorious/dcrec1s-clone/commit/c37d420f8...
>> [2]:http://gitorious.org/~tschamm/gitorious/tschamms-clone

Sub-uri deployments are, as you say, not really supported at the
moment and the patches submitted for it has always needed a bit of
work hence they haven't been merged. I'd recommend setting up a
virtualhost for a subdomain. Anyone interested in collecting the
patches mentioned and implement a clean solution that works both ways,
including images/css?

JS

Marius Mårnes Mathiesen

unread,
Jun 4, 2009, 4:28:59 AM6/4/09
to gito...@googlegroups.com
On 3. juni. 2009, at 19.06, Steve Hajducko wrote:
>
> We installed gitorious on a system where we have several other rails
> apps running and I've got it running in a mongrel+apache setup with
> mod_proxy.
>
> The problem we're running into is that we run the app as http://host.example.com/git/
> - We've found is that there are certain times when gitorious redirects
> the user back to /, which ends up being some other site rather than
> the app.

Did you tell Rails about the sub uri you're using? You can do this in
your environment file (config/environments/<rails_env>.rb) like so:

config.action_controller.relative_url_root = "/git"

This way, Rails knows that you're running Gitorious on a sub uri and
will adapt its route generation and helper methods to accommodate
this. For instance, the stylesheet_link_tag and image_tag helpers will
prepend "/git" to any css/image references it makes, and the routing
will do the same. Same goes for javascripts.

Once this is done, Gitorious should work in most cases, with a few
exceptions:

- Whenever there's a redirect_to "/" - this is sloppyness on our
behalf, sorry. I actually didn't find that many references to such
redirections, but luckily Rails supplies a special route for this:
root_path (and root_url). So whenever there's a:

redirect_to "/"

this should be changed to

redirect_to root_url

No need for a special gitorious_root_path, as this is already built
into Rails. We'd really appreciate a patch if you find the time to do
this!

As for image/css references, these should be okay wherever the
image_tag and stylesheet_link_tag are used. Image references inside
your CSS files, however, are a different issue, as these are static
files without any knowledge of the actual URL schemes used by
Gitorious. You could create a script that changes image references in
the CSS file to their correct location, however this would probably be
a tedious and error-prone process. Another solution would be to use
URL rewriting to intercept requests for images included in
stylesheets. This, however, would need to be done on the root of your
web servers, as this is where the requests will be handled. If you
create a rewrite rule that matches /images/* for files that don't
exist in the file system, these URLs could be rewritten to "/git/
images/*".

Regards,
- Marius

Gurce

unread,
Jul 11, 2012, 2:06:24 AM7/11/12
to gito...@googlegroups.com
Was wondering whether this sub-uri works successfully in latest version of Gitorious? I've tried a new local install (within a 'mydomain.com/gitorious' sub-folder), but the instant I log-in, I get re-directed to the base uri (same happens for log-out, just as with this initial thread). I grepp'ed around the code looking for any references to redirect_to "/" mentioned, but didn't find too many references to that around in the code anymore.

Regards,
Gurce
Reply all
Reply to author
Forward
0 new messages