ruby - 没有 config.ru 的启动 Rack 服务器?

标签 ruby config rack

我最近经常使用 Rack,并且想知道如何通过运行文件(例如 app.rb)来启动 Rack 服务器而不使用 config。 ru。这是可能的,还是更复杂的方法?

最佳答案

您可以改用内置的 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)

关于ruby - 没有 config.ru 的启动 Rack 服务器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10358347/

相关文章:

mysql - 执行语句是否不会在异常时回滚?

ruby - IRB 中的符号是什么意思?

iphone - 为 iPhone 编译 FreeType?

php - 升级 phpMyAdmin 到 4.3.4

ruby-on-rails - 如何覆盖 Spree 结帐表单和步骤流程?

ruby - 我应该将非 Ruby 文件放在我的 gem 中的什么位置?

ruby-on-rails - 部署Rails应用程序之前我需要做些什么?

将 boxen 优化排序到 4x4 Rack 中的算法

ruby-on-rails - 为什么 nginx 在开发环境中为我的 Rails 应用程序提供服务的速度非常慢?

Rack Warden : how can I access the message passed to the fail! 方法?