[Catalyst] Dispatching based on path and host/domain
Matt S Trout
dbix-class at trout.me.uk
Tue Apr 22 14:09:31 BST 2008
On Tue, Apr 22, 2008 at 12:07:36AM +0100, Curtis Fletcher wrote:
> Hi again guys.
>
> I've got a moderate sized Catalyst App in production now which I'm
> almost happy with :)
> It responds to one domain at the moment, and I'm pondering how to break
> out into two or more doing mostly the same thing on the same codebase
> and hopefully the same app instance.
>
> The app has a few "usual" controllers that handle specifics like the
> e-commerce, admin and soon, some database product access stuff. Any URI
> that fails to match a action defaults to the root controller and is then
> stripped and handled with a few calls to my model which builds the
> closest page from CMS style content.
>
> E.G.
>
> http://mydomain.com/cart/view
> Ends up calling the Local "view" method of myapp::Controller::Cart as
> you might expect but
> http://mydomain.com/businessunit1/product1/specialofferpage
>
> Ends up in the root controller and queries tables that holds dynamic
> URI-to-page content object mappings which then uses common code to
> render the page
>
> So for the CMS style data, if I add another domain "mydomain2" to the
> apache config for my myapp and another field to the UriPage table for
> "domain" and I'm almost there.
> But I'm at a bit of a loss at to what to do about:
> http://mydomain2.com/cart/view
> Ending up at myapp::Controller::Cart->view because that domain isn't
> supposed to have the e-commerce bit.
>
> I've been pondering how to make this distinction, maybe there is
> something I could get the dispatcher to do like:
>
> package myapp::Controller::Cart;
>
> sub view : Local Domain('mydomain.com')
> {
> }
Write an Action Class.
You can put whatever you want in the match() method. In your case,
return 0 if grep { $c->req->host =~ /$_/ } @{$self->attributes->{Domain}||[]}
looks about right.
--
Matt S Trout Need help with your Catalyst or DBIx::Class project?
Technical Director http://www.shadowcat.co.uk/catalyst/
Shadowcat Systems Ltd. Want a managed development or deployment platform?
http://chainsawblues.vox.com/ http://www.shadowcat.co.uk/servers/
More information about the Catalyst
mailing list