Getting the server port number during initialization

In the environment.rb I need to use the port number that the server is
being started under in an after_initialize block in order to register
my server with another server. I've looked in config
(Rails:Configuration) and ENV, but It doesn't look to be there. I know
that a workaround would be to set a PORT environment variable and use
that on the command line, for example. But I would rather use an
already existent method.

Hi all,

If you think data security should be a part of Rails 3 and that performance with large data set is also important, please visit this link and cast your vote.

http://rails.uservoice.com/pages/10012-rails/suggestions/327300-data-encryption-support

Hi John,

In the environment.rb I need to use the port number that the server is
being started under in an after_initialize block in order to register
my server with another server. I've looked in config
(Rails:Configuration) and ENV, but It doesn't look to be there. I know
that a workaround would be to set a PORT environment variable and use
that on the command line, for example. But I would rather use an
already existent method.

On a request-by-request basis you can test request.host_with_port. But,
AFAIK, Rails is unaware of the port used by the web server until that
server makes a request. If it were otherwise, it would be difficult to
run a pack of mongrels in front of the app. Perhaps if you said more
about what you mean by 'register my server with another server', we
could be more help.

HTH,
Bill

I have one admin-like server that provides information that is used
across a suite of other servers that provide various client-facing
services. In order to synchronize changes to ...

As I was typing, I realized that I was approaching the problem from
the wrong direction. Instead of providing the address from the client-
facing server, the admin-like server could get the address from the
request. Thanks for saying just enough.

You're welcome. Glad it helped.

Best regards,
Bill