如何将 Puma::Configuration 传递给 Sinatra?
How to pass Puma::Configuration to Sinatra?
这是我的网络应用程序:
class Front < Sinatra::Base
configure do
set :server, :puma
end
get '/' do
'Hello, world!'
end
end
我是这样启动的(请不要建议使用Rack):
Front.start!
这是我的 Puma 配置对象,我不知道如何传递给它:
require 'puma/configuration'
Puma::Configuration.new({ log_requests: true, debug: true })
说真的,怎么样?
你想传递一个对象还是一般的配置?对于最后一个选项,这是可能的,但 Puma 无论如何都不会记录任何内容(我不确定,但看起来你很担心 Puma 的日志记录设置)。
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'bundler/inline'
gemfile(true) do
gem 'sinatra'
gem 'puma'
gem 'openssl'
end
require 'sinatra/base'
class Front < Sinatra::Base
configure do
set :server, :puma
set :server_settings, log_requests: true, debug: true, environment: 'foo'
end
get '/' do
'Hello, world!'
end
end
Front.start!
配置紧密连接到您 运行 puma
服务器的方式。
运行 puma
- puma
CLI 命令的标准方式。为了配置 puma
配置文件 config/puma.rb
或 config/puma/<environment>.rb
应该提供(参见 example)。
但是你问的是如何将 Puma::Configuration
对象传递给 puma
。我想知道你为什么需要它,但 AFAIK 你需要在你的应用程序代码中以编程方式 运行 puma
服务器 Puma::Launcher
(参见 source code)
conf = Puma::Configuration.new do |user_config|
user_config.threads 1, 10
user_config.app do |env|
[200, {}, ["hello world"]]
end
end
Puma::Launcher.new(conf, events: Puma::Events.stdio).run
user_config.app
可以是任何可调用对象(与 Rack
接口兼容),如 Sinatra 应用程序。
希望对您有所帮助。
这是我的网络应用程序:
class Front < Sinatra::Base
configure do
set :server, :puma
end
get '/' do
'Hello, world!'
end
end
我是这样启动的(请不要建议使用Rack):
Front.start!
这是我的 Puma 配置对象,我不知道如何传递给它:
require 'puma/configuration'
Puma::Configuration.new({ log_requests: true, debug: true })
说真的,怎么样?
你想传递一个对象还是一般的配置?对于最后一个选项,这是可能的,但 Puma 无论如何都不会记录任何内容(我不确定,但看起来你很担心 Puma 的日志记录设置)。
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'bundler/inline'
gemfile(true) do
gem 'sinatra'
gem 'puma'
gem 'openssl'
end
require 'sinatra/base'
class Front < Sinatra::Base
configure do
set :server, :puma
set :server_settings, log_requests: true, debug: true, environment: 'foo'
end
get '/' do
'Hello, world!'
end
end
Front.start!
配置紧密连接到您 运行 puma
服务器的方式。
运行 puma
- puma
CLI 命令的标准方式。为了配置 puma
配置文件 config/puma.rb
或 config/puma/<environment>.rb
应该提供(参见 example)。
但是你问的是如何将 Puma::Configuration
对象传递给 puma
。我想知道你为什么需要它,但 AFAIK 你需要在你的应用程序代码中以编程方式 运行 puma
服务器 Puma::Launcher
(参见 source code)
conf = Puma::Configuration.new do |user_config|
user_config.threads 1, 10
user_config.app do |env|
[200, {}, ["hello world"]]
end
end
Puma::Launcher.new(conf, events: Puma::Events.stdio).run
user_config.app
可以是任何可调用对象(与 Rack
接口兼容),如 Sinatra 应用程序。
希望对您有所帮助。