Sinatra - 如何获取服务器的域名
我正在尝试在我的 Sinatra 应用程序中获取域名,但作为新手,我真的很难弄清楚如何做到这一点,而且我知道这一定是可能的!
Rack::Request#host_with_port
看起来很有希望,但我不知道如何从我的应用程序中获取它 - 如何在 Ruby 代码中从 Rack 获取内容?
或者还有另一种方法 - 我想我并不是真的想在每次请求发生时都这样做(虽然这还不错),但我认为如果我可以在应用程序时只执行一次会更好加载完毕。
有什么提示吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只需在代码中使用
request.host
即可。simply use
request.host
inside your code.看一下:
这样就可以看到所有的请求环境变量了。
我认为你正在寻找
Take a look at:
so you can see all the request environment variables.
I think that you are looking for