Sinatra 以编程方式获取端口和有关服务的其他信息

发布于 2024-09-03 17:15:27 字数 151 浏览 3 评论 0原文

我有一个 sinatra 服务 foo.rb

要在不同的端口上运行它,我会输入“ruby foo.rb -p 5000”。

当程序运行时,我希望能够获取端口(在本例中为 5000)和其他信息。有没有办法在应用程序运行时获取这样的信息?

谢谢

I have a sinatra service foo.rb

To run it I on a different port I would type "ruby foo.rb -p 5000".

While the program is running I would like to be able to get the port (in this case 5000) and other information. Is there a way to get info like this while the app is running?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

踏雪无痕 2024-09-10 17:15:27

您应该能够在任何 Sinatra 操作中使用 settings.port 访问它。

有关所有内置设置的列表,请参阅此页面

You should be able to get to it with settings.port in any Sinatra action.

See this page for a list of all the built-in settings.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文