rack-devel archive mirror (unofficial) https://groups.google.com/group/rack-devel
 help / color / mirror / code / Atom feed
* Middleware to dispatch request to multiple applications based on  request domain name
@ 2010-02-06 16:58 misza222
  2010-02-07 11:57 ` James Tucker
  0 siblings, 1 reply; 6+ messages in thread
From: misza222 @ 2010-02-06 16:58 UTC (permalink / raw)
  To: Rack Development

Hi,

Here is a problem I have.
There is an app which consists of multiple subapps. Requests needs to
be dispatched to the particular subapp based on the domain name.
I thought Rack::URLMap may be a solution but couldn't make it to work
so eventually I created my own rack middleware that allowed me to
achieve it. Here is how it looks like http://github.com/misza222/dispatch_by_domain
But am I reinventing a wheel here? Is there any way to achieve the
same thing with existing rack middleware?

Cheers,

Michal

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Middleware to dispatch request to multiple applications based on request domain name
  2010-02-06 16:58 Middleware to dispatch request to multiple applications based on request domain name misza222
@ 2010-02-07 11:57 ` James Tucker
  2010-02-07 22:36   ` misza222
  0 siblings, 1 reply; 6+ messages in thread
From: James Tucker @ 2010-02-07 11:57 UTC (permalink / raw)
  To: rack-devel


On 6 Feb 2010, at 16:58, misza222 wrote:

> Hi,
> 
> Here is a problem I have.
> There is an app which consists of multiple subapps. Requests needs to
> be dispatched to the particular subapp based on the domain name.
> I thought Rack::URLMap may be a solution but couldn't make it to work
> so eventually I created my own rack middleware that allowed me to
> achieve it. Here is how it looks like http://github.com/misza222/dispatch_by_domain
> But am I reinventing a wheel here? Is there any way to achieve the
> same thing with existing rack middleware?


map "http://mydomain.com/" do
  run App1.new
end

map "http://otherdomain.com/" do
  run App2.new
end

> 
> Cheers,
> 
> Michal

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Middleware to dispatch request to multiple applications based on request domain name
  2010-02-07 11:57 ` James Tucker
@ 2010-02-07 22:36   ` misza222
  2010-02-07 22:54     ` Daniel N
  2010-02-08 10:29     ` James Tucker
  0 siblings, 2 replies; 6+ messages in thread
From: misza222 @ 2010-02-07 22:36 UTC (permalink / raw)
  To: Rack Development

On 7 Feb, 11:57, James Tucker <jftuc...@gmail.com> wrote:
> On 6 Feb 2010, at 16:58, misza222 wrote:
>
> > Hi,
>
> > Here is a problem I have.
> > There is an app which consists of multiple subapps. Requests needs to
> > be dispatched to the particular subapp based on the domain name.
> > I thought Rack::URLMap may be a solution but couldn't make it to work
> > so eventually I created my own rack middleware that allowed me to
> > achieve it. Here is how it looks likehttp://github.com/misza222/dispatch_by_domain
> > But am I reinventing a wheel here? Is there any way to achieve the
> > same thing with existing rack middleware?
>
> map "http://mydomain.com/" do
>   run App1.new
> end
>
> map "http://otherdomain.com/" do
>   run App2.new
> end
>
>
>
> > Cheers,
>
> > Michal
>
>

Thanks James.

Where is 'map' method defined as I can't find it in the code?
And is there any way to make one of those apps a default one so it can
catch all unmatched paths?

--
Cheers,

Michal

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Middleware to dispatch request to multiple applications based on request domain name
  2010-02-07 22:36   ` misza222
@ 2010-02-07 22:54     ` Daniel N
  2010-02-08 10:29     ` James Tucker
  1 sibling, 0 replies; 6+ messages in thread
From: Daniel N @ 2010-02-07 22:54 UTC (permalink / raw)
  To: rack-devel

[-- Attachment #1: Type: text/plain, Size: 1243 bytes --]

Hi,

Usher or Rack::Mount which are rack based routers should be able to handle
this easily.

Cheers
Daniel


On Mon, Feb 8, 2010 at 9:36 AM, misza222 <misza222@gmail.com> wrote:

> On 7 Feb, 11:57, James Tucker <jftuc...@gmail.com> wrote:
> > On 6 Feb 2010, at 16:58, misza222 wrote:
> >
> > > Hi,
> >
> > > Here is a problem I have.
> > > There is an app which consists of multiple subapps. Requests needs to
> > > be dispatched to the particular subapp based on the domain name.
> > > I thought Rack::URLMap may be a solution but couldn't make it to work
> > > so eventually I created my own rack middleware that allowed me to
> > > achieve it. Here is how it looks likehttp://
> github.com/misza222/dispatch_by_domain
> > > But am I reinventing a wheel here? Is there any way to achieve the
> > > same thing with existing rack middleware?
> >
> > map "http://mydomain.com/" do
> >   run App1.new
> > end
> >
> > map "http://otherdomain.com/" do
> >   run App2.new
> > end
> >
> >
> >
> > > Cheers,
> >
> > > Michal
> >
> >
>
> Thanks James.
>
> Where is 'map' method defined as I can't find it in the code?
> And is there any way to make one of those apps a default one so it can
> catch all unmatched paths?
>
> --
> Cheers,
>
> Michal
>

[-- Attachment #2: Type: text/html, Size: 2117 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Middleware to dispatch request to multiple applications based on request domain name
  2010-02-07 22:36   ` misza222
  2010-02-07 22:54     ` Daniel N
@ 2010-02-08 10:29     ` James Tucker
  2010-02-08 21:17       ` misza222
  1 sibling, 1 reply; 6+ messages in thread
From: James Tucker @ 2010-02-08 10:29 UTC (permalink / raw)
  To: rack-devel


On 7 Feb 2010, at 22:36, misza222 wrote:

> On 7 Feb, 11:57, James Tucker <jftuc...@gmail.com> wrote:
>> On 6 Feb 2010, at 16:58, misza222 wrote:
>> 
>>> Hi,
>> 
>>> Here is a problem I have.
>>> There is an app which consists of multiple subapps. Requests needs to
>>> be dispatched to the particular subapp based on the domain name.
>>> I thought Rack::URLMap may be a solution but couldn't make it to work
>>> so eventually I created my own rack middleware that allowed me to
>>> achieve it. Here is how it looks likehttp://github.com/misza222/dispatch_by_domain
>>> But am I reinventing a wheel here? Is there any way to achieve the
>>> same thing with existing rack middleware?
>> 
>> map "http://mydomain.com/" do
>>   run App1.new
>> end
>> 
>> map "http://otherdomain.com/" do
>>   run App2.new
>> end
>> 
>> 
>> 
>>> Cheers,
>> 
>>> Michal
>> 
>> 
> 
> Thanks James.
> 
> Where is 'map' method defined as I can't find it in the code?

Rack::Builder in lib/rack/builder.rb

> And is there any way to make one of those apps a default one so it can
> catch all unmatched paths?

Yes, don't use a host for that app, and map to /

> 
> --
> Cheers,
> 
> Michal

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Middleware to dispatch request to multiple applications based on request domain name
  2010-02-08 10:29     ` James Tucker
@ 2010-02-08 21:17       ` misza222
  0 siblings, 0 replies; 6+ messages in thread
From: misza222 @ 2010-02-08 21:17 UTC (permalink / raw)
  To: Rack Development

On 8 Feb, 10:29, James Tucker <jftuc...@gmail.com> wrote:
> On 7 Feb 2010, at 22:36, misza222 wrote:
>
>
>
> > On 7 Feb, 11:57, James Tucker <jftuc...@gmail.com> wrote:
> >> On 6 Feb 2010, at 16:58, misza222 wrote:
>
> >>> Hi,
>
> >>> Here is a problem I have.
> >>> There is an app which consists of multiple subapps. Requests needs to
> >>> be dispatched to the particular subapp based on the domain name.
> >>> I thought Rack::URLMap may be a solution but couldn't make it to work
> >>> so eventually I created my own rack middleware that allowed me to
> >>> achieve it. Here is how it looks likehttp://github.com/misza222/dispatch_by_domain
> >>> But am I reinventing a wheel here? Is there any way to achieve the
> >>> same thing with existing rack middleware?
>
> >> map "http://mydomain.com/" do
> >>   run App1.new
> >> end
>
> >> map "http://otherdomain.com/" do
> >>   run App2.new
> >> end
>
> >>> Cheers,
>
> >>> Michal
>
> > Thanks James.
>
> > Where is 'map' method defined as I can't find it in the code?
>
> Rack::Builder in lib/rack/builder.rb
>
> > And is there any way to make one of those apps a default one so it can
> > catch all unmatched paths?
>
> Yes, don't use a host for that app, and map to /
>

That was my first guess too but unfortunately it doesn't work this
way.

map 'http://admin.localdomain/' do
  run AdminApp.new
end

map '/' do
  run DefaultApp.new
end

Always runs the default one.

>
>
> > --
> > Cheers,
>
> > Michal
>
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2010-02-08 21:59 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-02-06 16:58 Middleware to dispatch request to multiple applications based on request domain name misza222
2010-02-07 11:57 ` James Tucker
2010-02-07 22:36   ` misza222
2010-02-07 22:54     ` Daniel N
2010-02-08 10:29     ` James Tucker
2010-02-08 21:17       ` misza222

Code repositories for project(s) associated with this inbox:

	https://80x24.org/mirrors/rack.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).