Skip to content

Commit

Permalink
WIP.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Mar 17, 2024
1 parent 6c7bb45 commit 1904358
Show file tree
Hide file tree
Showing 15 changed files with 193 additions and 448 deletions.
4 changes: 2 additions & 2 deletions falcon.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ Gem::Specification.new do |spec|
spec.required_ruby_version = ">= 3.0"

spec.add_dependency "async"
spec.add_dependency "async-container", "~> 0.16.0"
spec.add_dependency "async-container", "~> 0.17.0"
spec.add_dependency "async-http", "~> 0.57"
spec.add_dependency "async-http-cache", "~> 0.4.0"
spec.add_dependency "async-io", "~> 1.22"
spec.add_dependency "async-service"
spec.add_dependency "async-service", "~> 0.6.0"
spec.add_dependency "bundler"
spec.add_dependency "localhost", "~> 1.1"
spec.add_dependency "openssl", "~> 3.0"
Expand Down
68 changes: 0 additions & 68 deletions lib/falcon/command/proxy.rb

This file was deleted.

71 changes: 0 additions & 71 deletions lib/falcon/command/redirect.rb

This file was deleted.

62 changes: 21 additions & 41 deletions lib/falcon/command/serve.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,12 @@

require_relative '../server'
require_relative '../endpoint'
require_relative '../controller/serve'
require_relative '../service/server'

require 'async/container'

require 'async/io/trap'
require 'async/io/host_endpoint'
require 'async/io/shared_endpoint'
require 'async/io/ssl_endpoint'

require 'async/http/client'

require 'samovar'

require 'rack/builder'

require 'bundler'

module Falcon
module Command
# Implements the `falcon serve` command. Designed for *development*.
Expand Down Expand Up @@ -53,29 +42,30 @@ class Serve < Samovar::Command
option '--threads <count>', "Number of threads (hybrid only).", type: Integer
end

# Options for the {endpoint}.
def container_options
@options.slice(:count, :forks, :threads)
end

def endpoint_options
@options.slice(:hostname, :port, :reuse_port, :timeout)
@options.slice(:hostname, :port, :timeout)
end

def environment
Async::Service::Environment.build do
include Falcon::Service::Server
def service
Async::Service::Environment.new(Falcon::Service::Server).with(
verbose: self.parent&.verbose?,
cache: @options[:cache],

rackup_path @options[:config]
container_options: self.container_options,
endpoint_options: self.endpoint_options,

container_options @options.slice(:count, :forks, :threads)
rackup_path: @options[:config],
preload: [@options[:preload]],
bind: @options[:bind],

preload @options[:preload]
name: "server",

verbose @parent&.verbose?

cache @options[:cache]

endpoint do
Endpoint.parse(@options[:bind], **endpoint_options)
end
end
endpoint: ->{Endpoint.parse(bind, **endpoint_options)}
)
end

# The container class to use.
Expand Down Expand Up @@ -114,20 +104,10 @@ def call
buffer.puts "- To reload configuration: kill -HUP #{Process.pid}"
end

begin
Bundler.require(:preload)
rescue Bundler::GemfileNotFound
# Ignore.
end

if Process.respond_to?(:warmup)
Process.warmup
elsif GC.respond_to?(:compact)
3.times{GC.start}
GC.compact
end
configuration = Async::Service::Configuration.new
configuration.add(self.service)

controller = Async::Service::Controller.new(container_class: self.container_class, environment: environment)
Async::Service::Controller.run(configuration, container_class: self.container_class)
end
end
end
Expand Down
55 changes: 13 additions & 42 deletions lib/falcon/command/virtual.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2018-2023, by Samuel Williams.
# Copyright, 2018-2024, by Samuel Williams.

require_relative '../controller/virtual'
require_relative '../service/virtual'
require_relative 'paths'

require 'samovar'
Expand Down Expand Up @@ -32,24 +32,14 @@ class Virtual < Samovar::Command

include Paths

# Prepare a new controller for the command.
def controller
Controller::Virtual.new(self)
end

# The URI to bind the `HTTPS` -> `falcon host` proxy.
def bind_secure
@options[:bind_secure]
end

# The URI to bind the `HTTP` -> `HTTPS` redirector.
def bind_insecure
@options[:bind_insecure]
end

# The connection timeout to use for incoming connections.
def timeout
@options[:timeout]
def service
Async::Service::Environment.new(Falcon::Service::Virtual).with(
verbose: self.parent&.verbose?,
configuration_paths: self.paths,
bind_insecure: @options[:bind_insecure],
bind_secure: @options[:bind_secure],
timeout: @options[:timeout]
)
end

# Prepare the environment and run the controller.
Expand All @@ -60,29 +50,10 @@ def call
buffer.puts "- To reload all sites: kill -HUP #{Process.pid}"
end

ENV['CONSOLE_LEVEL'] = 'debug'

self.controller.run
end

# The insecure endpoint for connecting to the {Redirect} instance.
def insecure_endpoint(**options)
Async::HTTP::Endpoint.parse(@options[:bind_insecure], **options)
end

# The secure endpoint for connecting to the {Proxy} instance.
def secure_endpoint(**options)
Async::HTTP::Endpoint.parse(@options[:bind_secure], **options)
end

# An endpoint suitable for connecting to the specified hostname.
def host_endpoint(hostname, **options)
endpoint = secure_endpoint(**options)

url = URI.parse(@options[:bind_secure])
url.hostname = hostname
configuration = self.configuration
configuration.add(self.service)

return Async::HTTP::Endpoint.new(url, hostname: endpoint.hostname)
Async::Service::Controller.run(configuration)
end
end
end
Expand Down
55 changes: 0 additions & 55 deletions lib/falcon/controller/host.rb

This file was deleted.

Loading

0 comments on commit 1904358

Please sign in to comment.