Class: Falcon::Command::Serve
- Inherits:
-
Samovar::Command
- Object
- Samovar::Command
- Falcon::Command::Serve
- Defined in:
- lib/falcon/command/serve.rb
Overview
Implements the ‘falcon serve` command. Designed for development.
Manages a Falcon::Controller::Serve instance which is responsible for running applications in a development environment.
Instance Method Summary collapse
-
#cache? ⇒ Boolean
Whether to enable the application HTTP cache.
-
#call ⇒ Object
Prepare the environment and run the controller.
-
#client ⇒ Object
Create a new client suitable for accessing the application.
-
#client_endpoint ⇒ Object
The endpoint suitable for a client to connect.
-
#container_class ⇒ Object
The container class to use.
-
#container_options ⇒ Object
Options for the container.
-
#controller ⇒ Object
Prepare a new controller for the command.
-
#endpoint ⇒ Object
The endpoint to bind to.
-
#endpoint_options ⇒ Object
Options for the #endpoint.
-
#load_app ⇒ Object
Load the rack application from the specified configuration path.
-
#verbose? ⇒ Boolean
Whether verbose logging is enabled.
Instance Method Details
#cache? ⇒ Boolean
Whether to enable the application HTTP cache.
91 92 93 |
# File 'lib/falcon/command/serve.rb', line 91 def cache? @options[:cache] end |
#call ⇒ Object
Prepare the environment and run the controller.
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# 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.}." 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.(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 ⇒ Object
Create a new client suitable for accessing the application.
125 126 127 |
# File 'lib/falcon/command/serve.rb', line 125 def client Async::HTTP::Client.new(client_endpoint) end |
#client_endpoint ⇒ Object
The endpoint suitable for a client to connect.
120 121 122 |
# File 'lib/falcon/command/serve.rb', line 120 def client_endpoint Async::HTTP::Endpoint.parse(@options[:bind], **) end |
#container_class ⇒ Object
The container class to use.
72 73 74 75 76 77 78 79 80 81 |
# 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 ⇒ Object
Options for the container. See Falcon::Controller::Serve#setup.
105 106 107 |
# File 'lib/falcon/command/serve.rb', line 105 def @options.slice(:count, :forks, :threads) end |
#controller ⇒ Object
Prepare a new controller for the command.
130 131 132 |
# File 'lib/falcon/command/serve.rb', line 130 def controller Controller::Serve.new(self) end |
#endpoint ⇒ Object
The endpoint to bind to.
115 116 117 |
# File 'lib/falcon/command/serve.rb', line 115 def endpoint Endpoint.parse(@options[:bind], **) end |
#endpoint_options ⇒ Object
Options for the #endpoint.
110 111 112 |
# File 'lib/falcon/command/serve.rb', line 110 def @options.slice(:hostname, :port, :reuse_port, :timeout) end |
#load_app ⇒ Object
Load the rack application from the specified configuration path.
97 98 99 100 101 |
# 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? ⇒ Boolean
Whether verbose logging is enabled.
85 86 87 |
# File 'lib/falcon/command/serve.rb', line 85 def verbose? @parent&.verbose? end |