FalconSourceFalconCommandRedirect

class Redirect

Implements the falcon redirect command.

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

Nested

Definitions

many :paths

One or more paths to the configuration files.

Signature

attribute Array(String)

def environment(**options)

Create the environment for the redirect service.

Signature

parameter options Hash

Additional options to pass to the environment.

returns Async::Service::Environment

The configured redirect environment.

Implementation

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

def configuration

Build the service configuration for the redirect.

Signature

returns Async::Service::Configuration

The service configuration.

Implementation

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

def call

Prepare the environment and run the controller.

Implementation

def call
	Console.logger.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

def endpoint(**options)

The endpoint to bind to.

Implementation

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

def redirect_endpoint(**options)

The template endpoint to redirect to.

Implementation

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