I'm trying to get the domain name in my Sinatra app but as a newbie I really am struggling to figure out how to do this, and I know it must be possible!
Rack::Request#host_with_port
looks promising, but I don't know how to get this from my app - how do I get stuff from Rack in my Ruby code?
Or is there another way - I'm thinking I don't really want to do this every time a request happens (although it's not too bad), but I thought it'd be better if I could just do it once when the application loads up.
Any hints?
Sinatra is powerful enough to develop a functioning web application with just a single file. Sinatra is recognized to be a good way for novice developers to get started in web application development in Ruby and can help prepare in learning for larger frameworks, including Rails.
Sinatra is a free and open source software web application library and domain-specific language written in Ruby. It is an alternative to other Ruby web application frameworks such as Ruby on Rails, Merb, Nitro, and Camping. It is dependent on the Rack web server interface. It is named after musician Frank Sinatra.
simply use request.host
inside your code.
get "/" do puts request.host #=> localhost end
Take a look at:
request.env.inspect
so you can see all the request environment variables.
I think that you are looking for
request.env["SERVER_NAME"]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With