Class: Falcon::Command::Virtual

Inherits:
Samovar::Command
  • Object
show all
Defined in:
lib/falcon/command/virtual.rb

Overview

Implements the ‘falcon virtual` command. Designed for deployment.

Manages a Controller::Virtual instance which is responsible for running the Proxy and Redirect instances.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#pathsObject (readonly)

One or more paths to the configuration files.



31
# File 'lib/falcon/command/virtual.rb', line 31

many :paths

Instance Method Details

#callObject

Prepare the environment and run the controller.



50
51
52
53
54
55
56
57
58
# File 'lib/falcon/command/virtual.rb', line 50

def call
	Console.logger.info(self) do |buffer|
		buffer.puts "Falcon Virtual v#{VERSION} taking flight!"
		buffer.puts "- To terminate: Ctrl-C or kill #{Process.pid}"
		buffer.puts "- To reload all sites: kill -HUP #{Process.pid}"
	end
	
	Async::Service::Controller.run(self.configuration)
end

#configurationObject



43
44
45
46
47
# File 'lib/falcon/command/virtual.rb', line 43

def configuration
	Async::Service::Configuration.new.tap do |configuration|
		configuration.add(self.environment)
	end
end

#environmentObject



33
34
35
36
37
38
39
40
41
# File 'lib/falcon/command/virtual.rb', line 33

def environment
	Async::Service::Environment.new(Falcon::Service::Virtual::Environment).with(
		verbose: self.parent&.verbose?,
		configuration_paths: self.paths,
		bind_insecure: @options[:bind_insecure],
		bind_secure: @options[:bind_secure],
		timeout: @options[:timeout],
	)
end

#host_endpoint(hostname, **options) ⇒ Object

An endpoint suitable for connecting to the specified hostname.



71
72
73
74
75
76
77
78
# File 'lib/falcon/command/virtual.rb', line 71

def host_endpoint(hostname, **options)
	endpoint = secure_endpoint(**options)
	
	url = URI.parse(@options[:bind_secure])
	url.hostname = hostname
	
	return Async::HTTP::Endpoint.new(url, hostname: endpoint.hostname)
end

#insecure_endpoint(**options) ⇒ Object

The insecure endpoint for connecting to the Redirect instance.



61
62
63
# File 'lib/falcon/command/virtual.rb', line 61

def insecure_endpoint(**options)
	Async::HTTP::Endpoint.parse(@options[:bind_insecure], **options)
end

#secure_endpoint(**options) ⇒ Object

The secure endpoint for connecting to the Proxy instance.



66
67
68
# File 'lib/falcon/command/virtual.rb', line 66

def secure_endpoint(**options)
	Async::HTTP::Endpoint.parse(@options[:bind_secure], **options)
end