From mboxrd@z Thu Jan 1 00:00:00 1970 Delivered-To: chneukirchen@gmail.com Received: by 10.64.139.39 with SMTP id qv7csp112500ieb; Mon, 24 Sep 2012 17:37:57 -0700 (PDT) Return-Path: Received-SPF: pass (google.com: domain of rack-devel+bncBDTLL3HA74NRBZHZQOBQKGQEUY3PK5A@googlegroups.com designates 10.50.12.199 as permitted sender) client-ip=10.50.12.199 Authentication-Results: mr.google.com; spf=pass (google.com: domain of rack-devel+bncBDTLL3HA74NRBZHZQOBQKGQEUY3PK5A@googlegroups.com designates 10.50.12.199 as permitted sender) smtp.mail=rack-devel+bncBDTLL3HA74NRBZHZQOBQKGQEUY3PK5A@googlegroups.com; dkim=pass header.i=rack-devel+bncBDTLL3HA74NRBZHZQOBQKGQEUY3PK5A@googlegroups.com Received: from mr.google.com ([10.50.12.199]) by 10.50.12.199 with SMTP id a7mr11888434igc.2.1348533476887 (num_hops = 1); Mon, 24 Sep 2012 17:37:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20120806; h=x-beenthere:date:from:to:message-id:in-reply-to:references:subject :mime-version:x-original-sender:reply-to:precedence:mailing-list :list-id:x-google-group-id:list-post:list-help:list-archive:sender :list-subscribe:list-unsubscribe:content-type; bh=reYP9JLXRviHZswWegepNSUFjjvvNJr5fsuxe27zSXU=; b=Lgh5V54fl8YNpITInQlldvCEfnLPgLzoq9kk9DmzJC5HupZDKK0FVCzlP8/U63hW/f toceDSvmLbtA4rrE9Hp/xij044IaxcmvZz9Kd1n5O68E7FhDeQCXmXwVLJIzk57hmSQZ Hufg6OEsiQnPzzzIFWyHjUFI8xd76Rbm++j0eTBwuuSmww8GFIYWZ21I7ea/GgSJKbNx oaVJVbjkCQGA9AIsZZ1ghvn0D9HwiXB8KEYwfE9i6FsevW8WLvcAlrmRpPM8n2u+g7zZ cTCLE184gnO/pTwCGNndJ7eMXMEBDqKt/nHSVdpdlr5+xv682v9aXsqrXMY0R4+VmoVM FbLg== Received: by 10.50.12.199 with SMTP id a7mr3508299igc.2.1348533476777; Mon, 24 Sep 2012 17:37:56 -0700 (PDT) X-BeenThere: rack-devel@googlegroups.com Received: by 10.50.51.234 with SMTP id n10ls4080133igo.3.canary; Mon, 24 Sep 2012 17:37:56 -0700 (PDT) Received: by 10.68.135.103 with SMTP id pr7mr3318518pbb.7.1348533476122; Mon, 24 Sep 2012 17:37:56 -0700 (PDT) Date: Mon, 24 Sep 2012 17:37:55 -0700 (PDT) From: armanx To: rack-devel@googlegroups.com Message-Id: In-Reply-To: References: <4c36a997-d560-4115-9261-1c0a7b7c24c9@googlegroups.com> Subject: Re: Possible to read request's host in config.ru? MIME-Version: 1.0 X-Original-Sender: armanx@gmail.com Reply-To: rack-devel@googlegroups.com Precedence: list Mailing-list: list rack-devel@googlegroups.com; contact rack-devel+owners@googlegroups.com List-ID: X-Google-Group-Id: 486215384060 List-Post: , List-Help: , List-Archive: Sender: rack-devel@googlegroups.com List-Subscribe: , List-Unsubscribe: , Content-Type: multipart/alternative; boundary="----=_Part_31_5485628.1348533475546" ------=_Part_31_5485628.1348533475546 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Thank you so much for prompt and useful explanation. On Saturday, September 22, 2012 3:42:32 AM UTC-7, Magnus Holm wrote: > > No, but this is what middleware are for: > > class ApplicationChooser > def initialize(apps) > @apps = apps > end > > def call(env) > @apps.each do |proc, app| > return app.call(env) if proc.call(env) > end > end > > run ApplicationChooser.new( > proc { |env| env["SERVER_NAME"] == "example.com" } => App1, > proc { |env| env["QUERY_STRING"] == "admin" } => App2, > proc { |env| true } => Default > ) > > // Magnus Holm > > > On Sat, Sep 22, 2012 at 12:32 PM, Arman > > wrote: > > Thanks for the quick answer. This definitely works. > > > > Our of curiosity, is it possible to see the host and other request > > information in config.ru? > > > > On Sep 22, 2012 3:04 AM, "Magnus Holm" > > wrote: > >> > >> It's already supported, you just need the trailing slash: > >> > >> map 'http://example1.com/' do > >> run MyApp::Example1 > >> end > >> > >> // Magnus Holm > >> > >> > >> On Sat, Sep 22, 2012 at 11:58 AM, armanx > > wrote: > >> > Is it possible to detect the incoming request's domain name (host) in > >> > config.ru? I'm trying to use URLMap to map different domains to > >> > different > >> > apps, all running on the same IP. Theoretically, I'm trying to > achieve > >> > this > >> > effect: > >> > > >> >> map 'http://example1.com' do > >> >> run MyApp::Example1 > >> >> end > >> >> > >> >> > >> >> > >> >> > >> >> > >> >> map 'http://example2.com' do > >> >> run MyApp::Example2 > >> >> end > >> > > >> > > >> > > >> > For example, if it was possible to read rack's SERVER_NAME in > config.ru, > >> > I > >> > would do something like: > >> > > >> >> if SERVER_NAME == 'example1.com' > >> >> map '/' do > >> >> run MyApp::Example1 > >> >> end > >> >> end > >> > > >> > > ------=_Part_31_5485628.1348533475546 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 7bit Thank you so much for prompt and useful explanation.


On Saturday, September 22, 2012 3:42:32 AM UTC-7, Magnus Holm wrote:
No, but this is what middleware are for:

class ApplicationChooser
  def initialize(apps)
    @apps = apps
  end

  def call(env)
    @apps.each do |proc, app|
      return app.call(env) if proc.call(env)
    end
end

run ApplicationChooser.new(
  proc { |env| env["SERVER_NAME"] == "example.com" } => App1,
  proc { |env| env["QUERY_STRING"] == "admin" } => App2,
  proc { |env| true } => Default
)

// Magnus Holm


On Sat, Sep 22, 2012 at 12:32 PM, Arman <arm...@gmail.com> wrote:
> Thanks for the quick answer. This definitely works.
>
> Our of curiosity, is it possible to see the host and other request
> information in config.ru?
>
> On Sep 22, 2012 3:04 AM, "Magnus Holm" <jud...@gmail.com> wrote:
>>
>> It's already supported, you just need the trailing slash:
>>
>> map 'http://example1.com/' do
>>   run MyApp::Example1
>> end
>>
>> // Magnus Holm
>>
>>
>> On Sat, Sep 22, 2012 at 11:58 AM, armanx <arm...@gmail.com> wrote:
>> > Is it possible to detect the incoming request's domain name (host) in
>> > config.ru? I'm trying to use URLMap to map different domains to
>> > different
>> > apps, all running on the same IP. Theoretically, I'm trying to achieve
>> > this
>> > effect:
>> >
>> >> map 'http://example1.com' do
>> >> run MyApp::Example1
>> >> end
>> >>
>> >>
>> >>
>> >>
>> >>
>> >> map 'http://example2.com' do
>> >> run MyApp::Example2
>> >> end
>> >
>> >
>> >
>> > For example, if it was possible to read rack's SERVER_NAME in config.ru,
>> > I
>> > would do something like:
>> >
>> >> if SERVER_NAME == 'example1.com'
>> >> map '/' do
>> >> run MyApp::Example1
>> >> end
>> >> end
>> >
>> >
------=_Part_31_5485628.1348533475546--