Sha256: 2d0806d3403db7d86f15e2a97bc47d26904d38dd992c520b0867ec4f1475e73b

Contents?: true

Size: 798 Bytes

Versions: 3

Compression:

Stored size: 798 Bytes

Contents

require 'rack/handler'

require_relative '../../falcon'

require 'async/reactor'
require 'async/io/host_endpoint'

module Rack
	module Handler
		module Falcon
			SCHEME = "http".freeze
			NAME = :falcon
			
			def self.endpoint_for(**options)
				host = options[:Host] || 'localhost'
				port = Integer(options[:Port] || 9292)
				
				return Async::IO::Endpoint.tcp(host, port)
			end
			
			def self.run(app, **options)
				endpoint = endpoint_for(**options)
				
				app = ::Falcon::Adapters::Rack.new(app)
				app = ::Falcon::Adapters::Rewindable.new(app)
				
				server = ::Falcon::Server.new(app, endpoint, Async::HTTP::Protocol::HTTP1, SCHEME)
				yield server if block_given?
				
				Async::Reactor.run do
					server.run
				end
			end
		end
		
		register Falcon::NAME, Falcon
	end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
falcon-0.35.2 lib/rack/handler/falcon.rb
falcon-0.35.1 lib/rack/handler/falcon.rb
falcon-0.35.0 lib/rack/handler/falcon.rb