class Falcon::Command::Serve

Implements the `falcon serve` command. Designed for development.

Manages a {Controller::Serve} instance which is responsible for running applications in a development environment.

Public Instance Methods

cache?() click to toggle source

Whether to enable the application HTTP cache. @returns [Boolean]

# File lib/falcon/command/serve.rb, line 91
def cache?
        @options[:cache]
end
call() click to toggle source

Prepare the environment and run the controller.

# File lib/falcon/command/serve.rb, line 135
def call
        Console.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
client() click to toggle source

Create a new client suitable for accessing the application.

# File lib/falcon/command/serve.rb, line 125
def client
        Async::HTTP::Client.new(client_endpoint)
end
client_endpoint() click to toggle source

The endpoint suitable for a client to connect.

# File lib/falcon/command/serve.rb, line 120
def client_endpoint
        Async::HTTP::Endpoint.parse(@options[:bind], **endpoint_options)
end
container_class() click to toggle source

The container class to use.

# File lib/falcon/command/serve.rb, line 72
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
container_options() click to toggle source

Options for the container. See {Controller::Serve#setup}.

# File lib/falcon/command/serve.rb, line 105
def container_options
        @options.slice(:count, :forks, :threads)
end
controller() click to toggle source

Prepare a new controller for the command.

# File lib/falcon/command/serve.rb, line 130
def controller
        Controller::Serve.new(self)
end
endpoint() click to toggle source

The endpoint to bind to.

# File lib/falcon/command/serve.rb, line 115
def endpoint
        Endpoint.parse(@options[:bind], **endpoint_options)
end
endpoint_options() click to toggle source

Options for the {endpoint}.

# File lib/falcon/command/serve.rb, line 110
def endpoint_options
        @options.slice(:hostname, :port, :reuse_port, :timeout)
end
load_app() click to toggle source

Load the rack application from the specified configuration path. @returns [Protocol::HTTP::Middleware]

# File lib/falcon/command/serve.rb, line 97
def load_app
        rack_app, _ = Rack::Builder.parse_file(@options[:config])
        
        return Server.middleware(rack_app, verbose: self.verbose?, cache: self.cache?)
end
verbose?() click to toggle source

Whether verbose logging is enabled. @returns [Boolean]

# File lib/falcon/command/serve.rb, line 85
def verbose?
        @parent&.verbose?
end