diff --git a/lib/falcon/command/serve.rb b/lib/falcon/command/serve.rb index d8a59595..2c71ffdb 100644 --- a/lib/falcon/command/serve.rb +++ b/lib/falcon/command/serve.rb @@ -50,7 +50,7 @@ def endpoint_options @options.slice(:hostname, :port, :timeout) end - def service + def environment Async::Service::Environment.new(Falcon::Service::Rackup::Environment).with( root: Dir.pwd, @@ -70,6 +70,12 @@ def service ) end + def configuration + Configuration.new.tap do |configuration| + configuration.add(self.environment) + end + end + # The container class to use. def container_class case @options[:container] @@ -106,10 +112,7 @@ def call buffer.puts "- To reload configuration: kill -HUP #{Process.pid}" end - configuration = Async::Service::Configuration.new - configuration.add(self.service) - - Async::Service::Controller.run(configuration, container_class: self.container_class) + Async::Service::Controller.run(self.configuration, container_class: self.container_class) end end end diff --git a/lib/falcon/command/virtual.rb b/lib/falcon/command/virtual.rb index 9ee3a312..028852d1 100644 --- a/lib/falcon/command/virtual.rb +++ b/lib/falcon/command/virtual.rb @@ -32,8 +32,8 @@ class Virtual < Samovar::Command include Paths - def service - Async::Service::Environment.new(Falcon::Service::Virtual).with( + def environment + Async::Service::Environment.new(Falcon::Service::Virtual::Environment).with( verbose: self.parent&.verbose?, configuration_paths: self.paths, bind_insecure: @options[:bind_insecure], @@ -42,6 +42,12 @@ def service ) end + def configuration + super.tap do |configuration| + configuration.add(self.environment) + end + end + # Prepare the environment and run the controller. def call Console.logger.info(self) do |buffer| @@ -50,10 +56,7 @@ def call buffer.puts "- To reload all sites: kill -HUP #{Process.pid}" end - configuration = self.configuration - configuration.add(self.service) - - Async::Service::Controller.run(configuration) + Async::Service::Controller.run(self.configuration) end end end diff --git a/lib/falcon/environments/application.rb b/lib/falcon/environments/application.rb index 7a5a3de3..2eba2974 100644 --- a/lib/falcon/environments/application.rb +++ b/lib/falcon/environments/application.rb @@ -14,6 +14,12 @@ module Falcon module Environments # A general application environment. Suitable for use with any {Protocol::HTTP::Middleware}. module Application + # The service class to use for the application. + # @returns [Class] + def service_class + ::Falcon::Service::Application + end + # The middleware stack for the application. # @returns [Protocol::HTTP::Middleware] def middleware @@ -51,12 +57,6 @@ def endpoint ) end - # The service class to use for the application. - # @returns [Class] - def service_class - ::Falcon::Service::Application - end - # Number of instances to start. # @returns [Integer | nil] def count diff --git a/lib/falcon/service/proxy.rb b/lib/falcon/service/proxy.rb index 0ed98218..b5792762 100644 --- a/lib/falcon/service/proxy.rb +++ b/lib/falcon/service/proxy.rb @@ -17,7 +17,7 @@ module Environment # The service class to use for the proxy. # @attribute [Class] def service_class - ::Falcon::Service::Proxy + Proxy end # The host that this proxy will receive connections for. diff --git a/lib/falcon/service/server.rb b/lib/falcon/service/server.rb index 815aaa10..91c8b35f 100644 --- a/lib/falcon/service/server.rb +++ b/lib/falcon/service/server.rb @@ -15,7 +15,7 @@ module Environment # The service class to use for the proxy. # @returns [Class] def service_class - ::Falcon::Service::Server + Server end # Options to use when creating the container. diff --git a/lib/falcon/service/virtual.rb b/lib/falcon/service/virtual.rb index 52a4ee64..08e21fc4 100644 --- a/lib/falcon/service/virtual.rb +++ b/lib/falcon/service/virtual.rb @@ -13,6 +13,12 @@ module Service # A virtual host is an application bound to a specific authority (essentially a hostname). The virtual controller manages multiple hosts and allows a single server to host multiple applications easily. class Virtual < Async::Service::Generic module Environment + # The service class to use for the virtual host. + # @returns [Class] + def service_class + Virtual + end + # All the falcon application configuration paths. # @returns [Array(String)] Paths to the falcon application configuration files. def configuration_paths diff --git a/test/falcon/command/serve.rb b/test/falcon/command/serve.rb index 7f6e38c4..cdc098cc 100644 --- a/test/falcon/command/serve.rb +++ b/test/falcon/command/serve.rb @@ -15,7 +15,8 @@ end it "can listen on specified port" do - controller = command.controller + configuration = command.configuration + controller = Async::Service::Controller.new(configuration.services.to_a) controller.start diff --git a/test/falcon/command/top.rb b/test/falcon/command/top.rb index 4c0ef721..d7de5ba5 100644 --- a/test/falcon/command/top.rb +++ b/test/falcon/command/top.rb @@ -16,8 +16,8 @@ ] serve = top.command - container = serve.controller - container.start + controller = Async::Service::Controller.new(serve.configuration) + controller.start Async do client = serve.client @@ -29,7 +29,7 @@ client.close end - container.stop + controller.stop end end end diff --git a/test/falcon/command/virtual.rb b/test/falcon/command/virtual.rb index 226e10c9..bb5eb5eb 100644 --- a/test/falcon/command/virtual.rb +++ b/test/falcon/command/virtual.rb @@ -28,8 +28,8 @@ } def around - # Wait for the container to start... - controller = command.controller + configuration = command.configuration + controller = Async::Service::Controller.new(configuration.services.to_a) controller.start