Class: Falcon::Command::Redirect

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

Overview

Implements the ‘falcon redirect` command.

Manages a Controller::Redirect instance which redirects insecure HTTP traffic to secure HTTPS endpoints.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Paths

#resolved_paths

Instance Attribute Details

#pathsObject (readonly)

One or more paths to the configuration files.



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

many :paths

Instance Method Details

#callObject

Prepare the environment and run the controller.



59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/falcon/command/redirect.rb', line 59

def call
	Console.info(self) do |buffer|
		buffer.puts "Falcon Redirect v#{VERSION} taking flight!"
		buffer.puts "- Binding to: #{@options[:bind]}"
		buffer.puts "- To terminate: Ctrl-C or kill #{Process.pid}"
		buffer.puts "- To reload: kill -HUP #{Process.pid}"
		
		self.resolved_paths do |path|
			buffer.puts "- Loading configuration from #{path}"
		end
	end
	
	Async::Service::Controller.run(self.configuration)
end

#configurationObject

Build the service configuration for the redirect.



52
53
54
55
56
# File 'lib/falcon/command/redirect.rb', line 52

def configuration
	Async::Service::Configuration.for(
		self.environment(environments: super.environments)
	)
end

#endpoint(**options) ⇒ Object

The endpoint to bind to.



75
76
77
# File 'lib/falcon/command/redirect.rb', line 75

def endpoint(**options)
	Async::HTTP::Endpoint.parse(@options[:bind], timeout: @options[:timeout], **options)
end

#environment(**options) ⇒ Object

Create the environment for the redirect service.



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/falcon/command/redirect.rb', line 38

def environment(**options)
	Async::Service::Environment.new(Falcon::Environment::Redirect).with(
		root: Dir.pwd,
		name: self.class.name,
		verbose: self.parent&.verbose?,
		url: @options[:bind],
		redirect_url: @options[:redirect],
		timeout: @options[:timeout],
		**options
	)
end

#redirect_endpoint(**options) ⇒ Object

The template endpoint to redirect to.



80
81
82
# File 'lib/falcon/command/redirect.rb', line 80

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