FalconSourceFalconEnvironmentServer

module Server

Provides an environment for hosting a web application that uses a Falcon server.

Definitions

def service_class

The service class to use for the proxy.

Signature

returns Class

Implementation

def service_class
	Service::Server
end

def authority

The server authority. Defaults to the server name.

Signature

returns String

Implementation

def authority
	self.name
end

def count

Number of instances to start. By default (when nil), uses Etc.nprocessors.

Signature

returns Integer | nil

Implementation

def count
	nil
end

def container_options

Options to use when creating the container.

Implementation

def container_options
	{
		restart: true,
		count: self.count,
		health_check_timeout: 30,
	}.compact
end

def url

The host that this server will receive connections for.

Implementation

def url
	"http://[::]:9292"
end

def timeout

The timeout used for client connections.

Implementation

def timeout
	nil
end

def endpoint_options

Options to use when creating the endpoint.

Implementation

def endpoint_options
	{
		reuse_address: true,
		timeout: self.timeout,
	}
end

def endpoint

The upstream endpoint that will handle incoming requests.

Signature

returns Async::HTTP::Endpoint

Implementation

def endpoint
	::Async::HTTP::Endpoint.parse(url).with(**endpoint_options)
end

def verbose

Whether to enable verbose logging.

Implementation

def verbose
	false
end

def cache

Whether to enable the HTTP cache for this server.

Implementation

def cache
	false
end

def client_endpoint

A client endpoint that can be used to connect to the server.

Signature

returns Async::HTTP::Endpoint

The client endpoint.

Implementation

def client_endpoint
	::Async::HTTP::Endpoint.parse(url)
end

def preload

Any scripts to preload before starting the server.

Signature

returns Array(String)

The list of scripts to preload.

Implementation

def preload
	[]
end

def make_server(endpoint)

Make a server instance using the given endpoint. The endpoint may be a bound endpoint, so we take care to specify the protocol and scheme as per the original endpoint.

Signature

parameter endpoint IO::Endpoint

The endpoint to bind to.

returns Falcon::Server

The server instance.

Implementation

def make_server(endpoint)
	Falcon::Server.new(self.middleware, endpoint, protocol: self.endpoint.protocol, scheme: self.endpoint.scheme)
end