Created
January 26, 2012 20:55
-
-
Save carlhoerberg/1685064 to your computer and use it in GitHub Desktop.
Webrick ssl example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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