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.
90 91 92 |
# File 'lib/falcon/command/serve.rb', line 90 def cache? @options[:cache] end |
#call ⇒ Object
Prepare the environment and run the controller.
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/falcon/command/serve.rb', line 134 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.
124 125 126 |
# File 'lib/falcon/command/serve.rb', line 124 def client Async::HTTP::Client.new(client_endpoint) end |
#client_endpoint ⇒ Object
The endpoint suitable for a client to connect.
119 120 121 |
# File 'lib/falcon/command/serve.rb', line 119 def client_endpoint Async::HTTP::Endpoint.parse(@options[:bind], **) end |
#container_class ⇒ Object
The container class to use.
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/falcon/command/serve.rb', line 71 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.
104 105 106 |
# File 'lib/falcon/command/serve.rb', line 104 def @options.slice(:count, :forks, :threads) end |
#controller ⇒ Object
Prepare a new controller for the command.
129 130 131 |
# File 'lib/falcon/command/serve.rb', line 129 def controller Controller::Serve.new(self) end |
#endpoint ⇒ Object
The endpoint to bind to.
114 115 116 |
# File 'lib/falcon/command/serve.rb', line 114 def endpoint Endpoint.parse(@options[:bind], **) end |
#endpoint_options ⇒ Object
Options for the #endpoint.
109 110 111 |
# File 'lib/falcon/command/serve.rb', line 109 def @options.slice(:hostname, :port, :reuse_port, :timeout) end |
#load_app ⇒ Object
Load the rack application from the specified configuration path.
96 97 98 99 100 |
# File 'lib/falcon/command/serve.rb', line 96 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.
84 85 86 |
# File 'lib/falcon/command/serve.rb', line 84 def verbose? @parent&.verbose? end |