【问题标题】:How to detect, that server is started in Sinatra/Thin如何检测,该服务器是在 Sinatra/Thin 中启动的
【发布时间】:2012-05-24 18:57:49
【问题描述】:

我有这样的代码:

Thread.new do
  builder = Rack::Builder.new do
    map('/'){ run Server }
  end
  Rack::Handler::Thin.run builder, :Port => 8585
end
#how do i detect, that Server is running here (or wait for it)

我如何检测到服务器正在运行并能够接收请求?

谢谢

【问题讨论】:

标签: ruby sinatra thin


【解决方案1】:

您可以使用defined? 方法来检查这一点,例如

if defined? Rack::Handler::Thin
   # We're running under Thin. Do stuff.
else
   # nope :(
end

【讨论】:

    【解决方案2】:

    在终端中使用curlcurl http://yourapp.com:8585/ 如果返回'/' 的页面,则服务器已启动。

    【讨论】:

    • 是的,我使用了那个解决方案,但似乎并不优雅
    猜你喜欢
    • 2012-01-27
    • 2019-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-27
    • 1970-01-01
    • 1970-01-01
    • 2020-09-24
    相关资源
    最近更新 更多