基本上我在一个Sinatra / GrapeAPI文件中有多个API应用程序
require 'sinatra'
require 'grape'
require 'webrick'
require 'webrick/https'
require 'openssl'
CERT_PATH = '/opt/myCA/server/'
class WebApp < Sinatra::Base
post '/' do
"Hellow, world!"
end
end
class Api1 < Grape::API
get '/test1' do
{xyz: 'test1' }
end
end
class Api2 < Grape::API
get '/test2' do
{xyz: 'test2' }
end
end
webrick_options1 = {
:Port => 8443,
:Logger => WEBrick::Log::new($stderr, WEBrick::Log::DEBUG),
:DocumentRoot => "/ruby/htdocs",
:SSLEnable => true,
:SSLVerifyClient => OpenSSL::SSL::VERIFY_NONE,
:SSLCertificate => OpenSSL::X509::Certificate.new( File.open(File.join(CERT_PATH, "my-server.crt")).read),
:SSLPrivateKey => OpenSSL::PKey::RSA.new( File.open(File.join(CERT_PATH, "my-server.key")).read),
:SSLCertName => [ [ "CN",WEBrick::Utils::getservername ] ]
}
webrick_options2 = {...}
Rack::Handler::WEBrick.run Api1, webrick_options1 # this will work
Rack::Handler::WEBrick.run Api2, webrick_options2 # but when I try another one,
# the other will not
Grape gem建议使用级联:
run Rack::Cascade.new [Api1, Api2, WebApp]
但是这会忽略我宝贵的SSL设置。
如何运行多个服务器配置?