gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 18:26:24 26 4
gpt4 key购买 nike

我最近经常使用 Rack,想知道如何在不使用 config 的情况下通过运行文件(例如 app.rb)来启动 Rack 服务器。 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com