1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
require 'bundler/setup'
port = ARGV[0] || 7000
secure = ARGV[1] == 'tls'
engine = ARGV[2] || 'thin'
spec = File.expand_path('../../spec', __FILE__)
require File.expand_path('../app', __FILE__)
Faye::WebSocket.load_adapter(engine)
case engine
when 'goliath'
class WebSocketServer < Goliath::API
def response(env)
App.call(env)
end
end
when 'puma'
require 'puma/binder'
require 'puma/events'
events = Puma::Events.new($stdout, $stderr)
binder = Puma::Binder.new(events)
binder.parse(["tcp://0.0.0.0:#{ port }"], App)
server = Puma::Server.new(App, events)
server.binder = binder
server.run.join
when 'rainbows'
rackup = Unicorn::Configurator::RACKUP
rackup[:port] = port
rackup[:set_listener] = true
options = rackup[:options]
options[:config_file] = File.expand_path('../rainbows.conf', __FILE__)
Rainbows::HttpServer.new(App, options).start.join
when 'thin'
thin = Rack::Handler.get('thin')
thin.run(App, :Host => '0.0.0.0', :Port => port) do |server|
if secure
server.ssl_options = {
:private_key_file => spec + '/server.key',
:cert_chain_file => spec + '/server.crt'
}
server.ssl = true
end
end
end
|