Get server address (rails server)

I have google map web application on rails.

google map needs API key that depends on server address.
ex) example.com:3000 and example.com:4000 need different API key

I have API key for several addresses in database
example.com:3000 [some key]
example.com:4000 [some key]
localhost:3000 [some key]
192.168.0.17:3000 [some key]

I want to select proper key based on server address when server start up

Now I am manually changing API keys everytime I need to do.

#1 Is there any way to get server address (rails server itself)?

#2 Can this work be done when server startup? not every session?

Thank you

sean

Answering the question #1 you can achieve this using the request.env[
‘HTTP_HOST’ ] variable, that will return you a string with the hostname
and the listening port, something like ‘localhost:8080’.
For the second one, I guess you could create like some constants for
storing those keys of your needs, but you’re not being very clear so I
can not go further. Hope this can help you.

Carlos.