class Falcon::Command::Serve

Manages a {Controller::Serve} instance which is responsible for running applications in a development environment.
Implements the ‘falcon serve` command. Designed for development.

def cache?

@returns [Boolean]
Whether to enable the application HTTP cache.
def cache?
	@options[:cache]
end

def call

Prepare the environment and run the controller.
def call
	Async.logger.info(self) do |buffer|
		buffer.puts "Falcon v#{VERSION} taking flight! Using #{self.container_class} #{self.container_options}."
		buffer.puts "- Binding to: #{self.endpoint}"
		buffer.puts "- To terminate: Ctrl-C or kill #{Process.pid}"
		buffer.puts "- To reload configuration: kill -HUP #{Process.pid}"
	end
	
	if path = @options[:preload]
		full_path = File.expand_path(path)
		load(full_path)
	end
	
	begin
		Bundler.require(:preload)
	rescue Bundler::GemfileNotFound
		# Ignore.
	end
	
	if GC.respond_to?(:compact)
		GC.compact
	end
	
	self.controller.run
end

def client

Create a new client suitable for accessing the application.
def client
	Async::HTTP::Client.new(client_endpoint)
end

def client_endpoint

The endpoint suitable for a client to connect.
def client_endpoint
	Async::HTTP::Endpoint.parse(@options[:bind], **endpoint_options)
end

def container_class

The container class to use.
def container_class
	case @options[:container]
	when :threaded
		return Async::Container::Threaded
	when :forked
		return Async::Container::Forked
	when :hybrid
		return Async::Container::Hybrid
	end
end

def container_options

See {Controller::Serve#setup}.
Options for the container.
def container_options
	@options.slice(:count, :forks, :threads)
end

def controller

Prepare a new controller for the command.
def controller
	Controller::Serve.new(self)
end

def endpoint

The endpoint to bind to.
def endpoint
	Endpoint.parse(@options[:bind], **endpoint_options)
end

def endpoint_options

Options for the {endpoint}.
def endpoint_options
	@options.slice(:hostname, :port, :reuse_port, :timeout)
end

def load_app

@returns [Protocol::HTTP::Middleware]
Load the rack application from the specified configuration path.
def load_app
	rack_app, _ = Rack::Builder.parse_file(@options[:config])
	
	return Server.middleware(rack_app, verbose: self.verbose?, cache: self.cache?)
end

def verbose?

@returns [Boolean]
Whether verbose logging is enabled.
def verbose?
	@parent&.verbose?
end