Sha256: 9896620ad474a47f4ef75d734b8fb123595dda1343a1f580aa2567f705ab8712

Contents?: true

Size: 1.07 KB

Versions: 3

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

require 'rack/handler'

require_relative '../../falcon'

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

module Rack
	module Handler
		# The falcon adaptor for the `rackup` executable.
		module Falcon
			# The default scheme.
			SCHEME = "http"
			NAME = :falcon
			
			# Generate an endpoint for the given `rackup` options.
			# @returns [Async::IO::Endpoint]
			def self.endpoint_for(**options)
				host = options[:Host] || 'localhost'
				port = Integer(options[:Port] || 9292)
				
				return Async::IO::Endpoint.tcp(host, port)
			end
			
			# Run the specified app using the given options:
			# @parameter app [Object] The rack middleware.
			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.36.7 lib/rack/handler/falcon.rb
falcon-0.36.6 lib/rack/handler/falcon.rb
falcon-0.36.5 lib/rack/handler/falcon.rb