Skip to content

Instantly share code, notes, and snippets.

@nahurst
Forked from TakahikoKawasaki/sinatra+thin+ssl.rb
Created January 15, 2016 00:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nahurst/42f3bedc1807cd9b7750 to your computer and use it in GitHub Desktop.
Save nahurst/42f3bedc1807cd9b7750 to your computer and use it in GitHub Desktop.
Sinatra + Thin + SSL
#!/usr/bin/env ruby
#
# This code snippet shows how to enable SSL in Sinatra+Thin.
#
require 'sinatra'
require 'thin'
class MyThinBackend < ::Thin::Backends::TcpServer
def initialize(host, port, options)
super(host, port)
@ssl = true
@ssl_options = options
end
end
configure do
set :environment, :production
set :bind, '0.0.0.0'
set :port, 443
set :server, "thin"
class << settings
def server_settings
{
:backend => MyThinBackend,
:private_key_file => File.dirname(__FILE__) + "/server.key",
:cert_chain_file => File.dirname(__FILE__) + "/server.crt",
:verify_peer => false
}
end
end
end
get '/' do
"Hello, SSL."
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment