Can I get the base URL of the Rack service outside of the request handler?

I would like to get the base URL of my web application from the Rack initialization code in mine config.ru. Sort of:

puts "Starting up on http://#{ENV['SERVER_NAME']}:#{ENV['SERVER_PORT']}/#{ENV['MOUNT_POINT']}..."

but I did not find anything like this accessible from outside the request handler. Obviously, I can do something like:

...
def get
  puts "Got a request for #{ENV['rack.url_scheme']}://#{ENV['HTTP_HOST']}#{ENV['REQUEST_PATH']}"
  ...

because the request is defined at this point. But at the beginning of my configuration file, none of these variables are defined.

Is there a Rack way I can use to access this information? Is this one of those cases when these things are not finalized until the start of the Rack? I seem to remember that other structures have a way to pass proc to a method that will execute it as soon as the environment is "ready." Does the rack have something like that?

+5
2

, Rack " ". , config.ru :

require 'rack'

app = proc { |env|
  [200, {'Content-Type' => 'text/plain'}, ['hello, world!']]
}

run Rack::URLMap.new('/myapp' => app,
                     '/' => app)

, . , , Rack CGI, Ruby , . "init" .

+2

, .

Rack , Rack. , . Sinatra:: Base #. , , . , , "mount_point" "SCRIPT_NAME".

. http://www.rubydoc.info/github/rack/rack/file/SPEC. , , , . , .

+2

All Articles