[Catalyst] Changing a base url in mod_perl

Ovid publiustemp-catalyst at yahoo.com
Fri Dec 30 23:18:56 CET 2005


--- Matt S Trout <dbix-class at trout.me.uk> wrote:

> Why do you need to specify this at build time? Under (e.g.) 
> mod_perl Catalyst will auto-detect it's base URL and Just 
> Handle It, and in the general case it's trivial to set the
> base URL from a config.yml

Hi Matt,

That's what I thought, but I'm doing something wrong.  I'm used to
programming under mod_perl, but not setting it up.  My httpd.conf has
something like the following:

    <VirtualHost *>
        ServerName   kinetic.catalyst
        DocumentRoot /usr/local/kinetic/root

        # kinetic catalyst app
        <Location /kinetic>
            SetHandler          modperl
            PerlResponseHandler Kinetic::UI::Catalyst
            Order allow,deny
            Allow from all
        </Location>
        
        # static files
        <Location />
            Order allow,deny
            Allow from all
        </Location>
    </VirtualHost>

If I get rid of the second Location and change the first one to
<Location />, everything works.  However, with the above setup, after
we log in from http://kinetic.catalyst/kinetic, I get sent to
http://kinetic.catalyst/login.

Kinetic::UI::Catalyst has this (simplified):

  sub begin : Private {
      my ( $self, $c ) = @_;
      unless ( $c->user ) {
          $c->req->action(undef);
          $c->forward( 'login', 'login' );
      }
  }

And the login controller has this:

    sub login : Local {
        my ( $self, $c ) = @_;

        $c->stash->{template} = 'login.tt';
        $c->session->{referer} ||= $c->req->path;
        if ( !$c->login() ) {
            $c->log->debug('login failed');
            $c->stash->{message} = 'Login failed.';
            $c->forward('Kinetic::UI::Catalyst::V::TT');
        }
        else {
            if ( $c->session->{referer} =~ m{^/?login} ) {
                $c->session->{referer} = '/';
            }
            $c->log->debug('login succeeded');
            $c->res->redirect( $c->session->{referer} || '/' );
        }
    }

Now that I look at this, I'm guessing that I am handling the referer
wrong, but I can't really tell.  I'm sort of cargo-culting this along.

Cheers,
Ovid

-- 
If this message is a response to a question on a mailing list, please send follow up questions to the list.

Web Programming with Perl -- http://users.easystreet.com/ovid/cgi_course/



More information about the Catalyst mailing list