Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Webrick ssl example
require 'sinatra/base'
require 'openssl'
require 'webrick'
require 'webrick/https'
class App1 < Sinatra::Base
get '/' do
'app1'
end
end
class App2 < Sinatra::Base
get '/' do
'app2'
end
end
app = Rack::Builder.new do
map '/app1' do
run App1
end
map '/app2' do
run App2
end
end
webrick_options = {
:Port => 8443,
:Logger => WEBrick::Log::new($stdout, WEBrick::Log::DEBUG),
:DocumentRoot => "./public",
:SSLEnable => true,
:SSLCertificate => OpenSSL::X509::Certificate.new( File.open("./ssl.pem").read),
:SSLPrivateKey => OpenSSL::PKey::RSA.new( File.open("./ssl.key").read),
:SSLCertName => [ [ "CN",WEBrick::Utils::getservername ] ]
}
Rack::Handler::WEBrick.run app, webrick_options
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.