Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Possible to read request's host in config.ru?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
armanx  
View profile  
 More options Sep 22 2012, 5:58 am
From: armanx <arm...@gmail.com>
Date: Sat, 22 Sep 2012 02:58:00 -0700 (PDT)
Subject: Possible to read request's host in config.ru?

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'


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Magnus Holm  
View profile  
 More options Sep 22 2012, 6:04 am
From: Magnus Holm <judo...@gmail.com>
Date: Sat, 22 Sep 2012 12:04:03 +0200
Local: Sat, Sep 22 2012 6:04 am
Subject: Re: Possible to read request's host in config.ru?
It's already supported, you just need the trailing slash:

map 'http://example1.com/' do
  run MyApp::Example1
end

// Magnus Holm


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Arman  
View profile  
 More options Sep 22 2012, 6:32 am
From: Arman <arm...@gmail.com>
Date: Sat, 22 Sep 2012 03:32:30 -0700
Local: Sat, Sep 22 2012 6:32 am
Subject: Re: Possible to read request's host in config.ru?

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" <judo...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Magnus Holm  
View profile   Translate to Translated (View Original)
 More options Sep 22 2012, 6:42 am
From: Magnus Holm <judo...@gmail.com>
Date: Sat, 22 Sep 2012 12:42:11 +0200
Local: Sat, Sep 22 2012 6:42 am
Subject: Re: Possible to read request's host in config.ru?
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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
armanx  
View profile  
 More options Sep 24 2012, 8:37 pm
From: armanx <arm...@gmail.com>
Date: Mon, 24 Sep 2012 17:37:55 -0700 (PDT)
Local: Mon, Sep 24 2012 8:37 pm
Subject: Re: Possible to read request's host in config.ru?

Thank you so much for prompt and useful explanation.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic