【问题标题】:Startup Rack server without config.ru?没有 config.ru 的启动机架服务器?
【发布时间】:2012-04-28 06:25:15
【问题描述】:

我最近一直在搞乱 Rack,想知道如何在不使用 config.ru 的情况下通过运行文件(例如 app.rb)来启动 Rack 服务器。这是可能的,还是更复杂的方法?

【问题讨论】:

    标签: ruby config rack


    【解决方案1】:

    您可以改用内置的 WEBrick 服务器。因此,您通常可能会遇到这样的情况:

    # app.rb
    class App
      def call(env)
        return [200, {"Content-Type" => "text/html"}, "Hello, World!"]
      end
    end
    
    # config.ru
    require 'app'
    run App.new
    

    您可以改为整合它并直接运行ruby app.rb

    #app.rb
    class App
      def call(env)
        return [200, {"Content-Type" => "text/html"}, "Hello, World!"]
      end
    end
    
    Rack::Handler::WEBrick.run(App.new, :Port => 9292)
    

    【讨论】:

    • 谢谢,不过我已经开始使用类似Rack::Server.start(...) 的东西,而不是纯 WEBBrick 服务器(也允许您使用瘦服务器)。感谢您的提示!
    猜你喜欢
    • 1970-01-01
    • 2011-09-14
    • 2015-02-13
    • 2014-02-09
    • 2021-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多