falcon 0.43.0 → 0.44.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/changes.md +22 -0
- data/lib/falcon/command/host.rb +6 -32
- data/lib/falcon/command/proxy.rb +20 -15
- data/lib/falcon/command/redirect.rb +21 -15
- data/lib/falcon/command/serve.rb +41 -65
- data/lib/falcon/command/top.rb +1 -1
- data/lib/falcon/command/virtual.rb +15 -23
- data/lib/falcon/configuration.rb +26 -124
- data/lib/falcon/environment/application.rb +60 -0
- data/lib/falcon/environment/lets_encrypt_tls.rb +34 -0
- data/lib/falcon/environment/proxy.rb +109 -0
- data/lib/falcon/environment/rack.rb +20 -0
- data/lib/falcon/environment/rackup.rb +26 -0
- data/lib/falcon/environment/redirect.rb +50 -0
- data/lib/falcon/environment/self_signed_tls.rb +45 -0
- data/lib/falcon/environment/server.rb +69 -0
- data/lib/falcon/environment/supervisor.rb +40 -0
- data/lib/falcon/environment/tls.rb +97 -0
- data/lib/falcon/{environments.rb → environment.rb} +3 -4
- data/lib/falcon/service/server.rb +84 -0
- data/lib/falcon/service/supervisor.rb +4 -3
- data/lib/falcon/{controller → service}/virtual.rb +71 -18
- data/lib/falcon/version.rb +2 -2
- data/license.md +2 -0
- data.tar.gz.sig +0 -0
- metadata +24 -26
- metadata.gz.sig +0 -0
- data/lib/.DS_Store +0 -0
- data/lib/falcon/controller/host.rb +0 -55
- data/lib/falcon/controller/proxy.rb +0 -109
- data/lib/falcon/controller/redirect.rb +0 -59
- data/lib/falcon/controller/serve.rb +0 -110
- data/lib/falcon/environments/application.rb +0 -56
- data/lib/falcon/environments/lets_encrypt_tls.rb +0 -30
- data/lib/falcon/environments/proxy.rb +0 -22
- data/lib/falcon/environments/rack.rb +0 -33
- data/lib/falcon/environments/self_signed_tls.rb +0 -38
- data/lib/falcon/environments/supervisor.rb +0 -34
- data/lib/falcon/environments/tls.rb +0 -86
- data/lib/falcon/service/application.rb +0 -99
- data/lib/falcon/service/generic.rb +0 -61
- data/lib/falcon/service/proxy.rb +0 -49
- data/lib/falcon/services.rb +0 -82
@@ -1,25 +1,76 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Released under the MIT License.
|
4
|
-
# Copyright,
|
4
|
+
# Copyright, 2024, by Samuel Williams.
|
5
5
|
|
6
|
-
require 'async/
|
6
|
+
require 'async/service/generic'
|
7
7
|
|
8
8
|
module Falcon
|
9
|
-
module
|
9
|
+
module Service
|
10
10
|
# A controller which mananages several virtual hosts.
|
11
11
|
# Spawns instances of {Proxy} and {Redirect} to handle incoming requests.
|
12
12
|
#
|
13
13
|
# A virtual host is an application bound to a specific authority (essentially a hostname). The virtual controller manages multiple hosts and allows a single server to host multiple applications easily.
|
14
|
-
class Virtual < Async::
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
class Virtual < Async::Service::Generic
|
15
|
+
module Environment
|
16
|
+
# The service class to use for the virtual host.
|
17
|
+
# @returns [Class]
|
18
|
+
def service_class
|
19
|
+
Virtual
|
20
|
+
end
|
21
|
+
|
22
|
+
def name
|
23
|
+
service_class.name
|
24
|
+
end
|
25
|
+
|
26
|
+
# All the falcon application configuration paths.
|
27
|
+
# @returns [Array(String)] Paths to the falcon application configuration files.
|
28
|
+
def configuration_paths
|
29
|
+
["/srv/http/*/falcon.rb"]
|
30
|
+
end
|
19
31
|
|
20
|
-
|
32
|
+
def configuration
|
33
|
+
::Async::Service::Configuration.load(configuration_paths)
|
34
|
+
end
|
35
|
+
|
36
|
+
# The URI to bind the `HTTPS` -> `falcon host` proxy.
|
37
|
+
def bind_secure
|
38
|
+
"https://[::]:443"
|
39
|
+
end
|
40
|
+
|
41
|
+
# The URI to bind the `HTTP` -> `HTTPS` redirector.
|
42
|
+
def bind_insecure
|
43
|
+
"http://[::]:80"
|
44
|
+
end
|
21
45
|
|
22
|
-
|
46
|
+
# The connection timeout to use for incoming connections.
|
47
|
+
def timeout
|
48
|
+
10.0
|
49
|
+
end
|
50
|
+
|
51
|
+
# # The insecure endpoint for connecting to the {Redirect} instance.
|
52
|
+
# def insecure_endpoint(**options)
|
53
|
+
# Async::HTTP::Endpoint.parse(bind_insecure, **options)
|
54
|
+
# end
|
55
|
+
|
56
|
+
# # The secure endpoint for connecting to the {Proxy} instance.
|
57
|
+
# def secure_endpoint(**options)
|
58
|
+
# Async::HTTP::Endpoint.parse(bind_secure, **options)
|
59
|
+
# end
|
60
|
+
|
61
|
+
# # An endpoint suitable for connecting to the specified hostname.
|
62
|
+
# def host_endpoint(hostname, **options)
|
63
|
+
# endpoint = secure_endpoint(**options)
|
64
|
+
|
65
|
+
# url = URI.parse(bind_secure)
|
66
|
+
# url.hostname = hostname
|
67
|
+
|
68
|
+
# return Async::HTTP::Endpoint.new(url, hostname: endpoint.hostname)
|
69
|
+
# end
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.included(target)
|
73
|
+
target.include(Environnment)
|
23
74
|
end
|
24
75
|
|
25
76
|
# Drop privileges according to the user and group of the specified path.
|
@@ -70,7 +121,9 @@ module Falcon
|
|
70
121
|
end
|
71
122
|
|
72
123
|
container.reload do
|
73
|
-
@
|
124
|
+
evaluator = @environment.evaluator
|
125
|
+
|
126
|
+
evaluator.configuration_paths.each do |path|
|
74
127
|
path = File.expand_path(path)
|
75
128
|
root = File.dirname(path)
|
76
129
|
|
@@ -79,18 +132,18 @@ module Falcon
|
|
79
132
|
|
80
133
|
container.spawn(name: "Falcon Redirector", restart: true, key: :redirect) do |instance|
|
81
134
|
instance.exec(falcon_path, "redirect",
|
82
|
-
"--bind",
|
83
|
-
"--timeout",
|
84
|
-
"--redirect",
|
85
|
-
|
135
|
+
"--bind", evaluator.bind_insecure,
|
136
|
+
"--timeout", evaluator.timeout.to_s,
|
137
|
+
"--redirect", evaluator.bind_secure,
|
138
|
+
*evaluator.configuration_paths, ready: false
|
86
139
|
)
|
87
140
|
end
|
88
141
|
|
89
142
|
container.spawn(name: "Falcon Proxy", restart: true, key: :proxy) do |instance|
|
90
143
|
instance.exec(falcon_path, "proxy",
|
91
|
-
"--bind",
|
92
|
-
"--timeout",
|
93
|
-
|
144
|
+
"--bind", evaluator.bind_secure,
|
145
|
+
"--timeout", evaluator.timeout.to_s,
|
146
|
+
*evaluator.configuration_paths, ready: false
|
94
147
|
)
|
95
148
|
end
|
96
149
|
end
|
data/lib/falcon/version.rb
CHANGED
data/license.md
CHANGED
@@ -19,6 +19,8 @@ Copyright, 2021, by Olle Jonsson.
|
|
19
19
|
Copyright, 2023, by Nick Janetakis.
|
20
20
|
Copyright, 2024, by Peter Schrammel.
|
21
21
|
Copyright, 2024, by Santiago Bartesaghi.
|
22
|
+
Copyright, 2024, by Trevor Turk.
|
23
|
+
Copyright, 2024, by dependabot[bot].
|
22
24
|
|
23
25
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
24
26
|
of this software and associated documentation files (the "Software"), to deal
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: falcon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.44.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
@@ -11,6 +11,7 @@ authors:
|
|
11
11
|
- Kyle Tam
|
12
12
|
- Mitsutaka Mimura
|
13
13
|
- Sho Ito
|
14
|
+
- Trevor Turk
|
14
15
|
- Colby Swandale
|
15
16
|
- Daniel Evans
|
16
17
|
- Kent Gruber
|
@@ -23,6 +24,7 @@ authors:
|
|
23
24
|
- Sh Lin
|
24
25
|
- Tad Thorley
|
25
26
|
- Tasos Latsas
|
27
|
+
- dependabot[bot]
|
26
28
|
autorequire:
|
27
29
|
bindir: bin
|
28
30
|
cert_chain:
|
@@ -55,7 +57,7 @@ cert_chain:
|
|
55
57
|
Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
|
56
58
|
voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
|
57
59
|
-----END CERTIFICATE-----
|
58
|
-
date: 2024-
|
60
|
+
date: 2024-03-25 00:00:00.000000000 Z
|
59
61
|
dependencies:
|
60
62
|
- !ruby/object:Gem::Dependency
|
61
63
|
name: async
|
@@ -77,14 +79,14 @@ dependencies:
|
|
77
79
|
requirements:
|
78
80
|
- - "~>"
|
79
81
|
- !ruby/object:Gem::Version
|
80
|
-
version: 0.
|
82
|
+
version: '0.17'
|
81
83
|
type: :runtime
|
82
84
|
prerelease: false
|
83
85
|
version_requirements: !ruby/object:Gem::Requirement
|
84
86
|
requirements:
|
85
87
|
- - "~>"
|
86
88
|
- !ruby/object:Gem::Version
|
87
|
-
version: 0.
|
89
|
+
version: '0.17'
|
88
90
|
- !ruby/object:Gem::Dependency
|
89
91
|
name: async-http
|
90
92
|
requirement: !ruby/object:Gem::Requirement
|
@@ -128,19 +130,19 @@ dependencies:
|
|
128
130
|
- !ruby/object:Gem::Version
|
129
131
|
version: '1.22'
|
130
132
|
- !ruby/object:Gem::Dependency
|
131
|
-
name:
|
133
|
+
name: async-service
|
132
134
|
requirement: !ruby/object:Gem::Requirement
|
133
135
|
requirements:
|
134
136
|
- - "~>"
|
135
137
|
- !ruby/object:Gem::Version
|
136
|
-
version:
|
138
|
+
version: 0.10.0
|
137
139
|
type: :runtime
|
138
140
|
prerelease: false
|
139
141
|
version_requirements: !ruby/object:Gem::Requirement
|
140
142
|
requirements:
|
141
143
|
- - "~>"
|
142
144
|
- !ruby/object:Gem::Version
|
143
|
-
version:
|
145
|
+
version: 0.10.0
|
144
146
|
- !ruby/object:Gem::Dependency
|
145
147
|
name: bundler
|
146
148
|
requirement: !ruby/object:Gem::Requirement
|
@@ -236,7 +238,7 @@ files:
|
|
236
238
|
- bake/falcon/supervisor.rb
|
237
239
|
- bin/falcon
|
238
240
|
- bin/falcon-host
|
239
|
-
-
|
241
|
+
- changes.md
|
240
242
|
- lib/falcon.rb
|
241
243
|
- lib/falcon/command.rb
|
242
244
|
- lib/falcon/command/host.rb
|
@@ -248,31 +250,27 @@ files:
|
|
248
250
|
- lib/falcon/command/top.rb
|
249
251
|
- lib/falcon/command/virtual.rb
|
250
252
|
- lib/falcon/configuration.rb
|
251
|
-
- lib/falcon/controller/host.rb
|
252
|
-
- lib/falcon/controller/proxy.rb
|
253
|
-
- lib/falcon/controller/redirect.rb
|
254
|
-
- lib/falcon/controller/serve.rb
|
255
|
-
- lib/falcon/controller/virtual.rb
|
256
253
|
- lib/falcon/endpoint.rb
|
257
|
-
- lib/falcon/
|
258
|
-
- lib/falcon/
|
259
|
-
- lib/falcon/
|
260
|
-
- lib/falcon/
|
261
|
-
- lib/falcon/
|
262
|
-
- lib/falcon/
|
263
|
-
- lib/falcon/
|
264
|
-
- lib/falcon/
|
254
|
+
- lib/falcon/environment.rb
|
255
|
+
- lib/falcon/environment/application.rb
|
256
|
+
- lib/falcon/environment/lets_encrypt_tls.rb
|
257
|
+
- lib/falcon/environment/proxy.rb
|
258
|
+
- lib/falcon/environment/rack.rb
|
259
|
+
- lib/falcon/environment/rackup.rb
|
260
|
+
- lib/falcon/environment/redirect.rb
|
261
|
+
- lib/falcon/environment/self_signed_tls.rb
|
262
|
+
- lib/falcon/environment/server.rb
|
263
|
+
- lib/falcon/environment/supervisor.rb
|
264
|
+
- lib/falcon/environment/tls.rb
|
265
265
|
- lib/falcon/middleware/proxy.rb
|
266
266
|
- lib/falcon/middleware/redirect.rb
|
267
267
|
- lib/falcon/middleware/verbose.rb
|
268
268
|
- lib/falcon/proxy_endpoint.rb
|
269
269
|
- lib/falcon/railtie.rb
|
270
270
|
- lib/falcon/server.rb
|
271
|
-
- lib/falcon/service/
|
272
|
-
- lib/falcon/service/generic.rb
|
273
|
-
- lib/falcon/service/proxy.rb
|
271
|
+
- lib/falcon/service/server.rb
|
274
272
|
- lib/falcon/service/supervisor.rb
|
275
|
-
- lib/falcon/
|
273
|
+
- lib/falcon/service/virtual.rb
|
276
274
|
- lib/falcon/tls.rb
|
277
275
|
- lib/falcon/version.rb
|
278
276
|
- lib/rack/handler/falcon.rb
|
@@ -299,7 +297,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
299
297
|
- !ruby/object:Gem::Version
|
300
298
|
version: '0'
|
301
299
|
requirements: []
|
302
|
-
rubygems_version: 3.5.
|
300
|
+
rubygems_version: 3.5.3
|
303
301
|
signing_key:
|
304
302
|
specification_version: 4
|
305
303
|
summary: A fast, asynchronous, rack-compatible web server.
|
metadata.gz.sig
CHANGED
Binary file
|
data/lib/.DS_Store
DELETED
Binary file
|
@@ -1,55 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Released under the MIT License.
|
4
|
-
# Copyright, 2020-2023, by Samuel Williams.
|
5
|
-
|
6
|
-
require_relative '../services'
|
7
|
-
|
8
|
-
require 'async/container/controller'
|
9
|
-
|
10
|
-
module Falcon
|
11
|
-
module Controller
|
12
|
-
# A generic controller for serving an application.
|
13
|
-
# Hosts several {Services} based on the command configuration.
|
14
|
-
#
|
15
|
-
# The configuration is provided by {Command::Host} and is typically loaded from a `falcon.rb` file. See {Configuration#load_file} for more details.
|
16
|
-
class Host < Async::Container::Controller
|
17
|
-
# Initialize the virtual controller.
|
18
|
-
# @parameter command [Command::Host] The user-specified command-line options.
|
19
|
-
def initialize(command, **options)
|
20
|
-
@command = command
|
21
|
-
|
22
|
-
@configuration = command.configuration
|
23
|
-
@services = Services.new(@configuration)
|
24
|
-
|
25
|
-
super(**options)
|
26
|
-
end
|
27
|
-
|
28
|
-
# Create the controller as specified by the command.
|
29
|
-
# e.g. `Async::Container::Forked`.
|
30
|
-
def create_container
|
31
|
-
@command.container_class.new
|
32
|
-
end
|
33
|
-
|
34
|
-
# Start all specified services.
|
35
|
-
def start
|
36
|
-
@services.start
|
37
|
-
|
38
|
-
super
|
39
|
-
end
|
40
|
-
|
41
|
-
# Setup all specified services into the container.
|
42
|
-
# @parameter container [Async::Container::Generic]
|
43
|
-
def setup(container)
|
44
|
-
@services.setup(container)
|
45
|
-
end
|
46
|
-
|
47
|
-
# Stop all specified services.
|
48
|
-
def stop(*)
|
49
|
-
@services.stop
|
50
|
-
|
51
|
-
super
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
@@ -1,109 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Released under the MIT License.
|
4
|
-
# Copyright, 2020-2023, by Samuel Williams.
|
5
|
-
|
6
|
-
require 'async/container/controller'
|
7
|
-
|
8
|
-
require_relative 'serve'
|
9
|
-
require_relative '../middleware/proxy'
|
10
|
-
require_relative '../service/proxy'
|
11
|
-
|
12
|
-
require_relative '../tls'
|
13
|
-
|
14
|
-
module Falcon
|
15
|
-
module Controller
|
16
|
-
# A controller for proxying requests.
|
17
|
-
class Proxy < Serve
|
18
|
-
# The default SSL session identifier.
|
19
|
-
DEFAULT_SESSION_ID = "falcon"
|
20
|
-
|
21
|
-
# Initialize the proxy controller.
|
22
|
-
# @parameter command [Command::Proxy] The user-specified command-line options.
|
23
|
-
# @parameter session_id [String] The SSL session identifier to use for the session cache.
|
24
|
-
def initialize(command, session_id: DEFAULT_SESSION_ID, **options)
|
25
|
-
super(command, **options)
|
26
|
-
|
27
|
-
@session_id = session_id
|
28
|
-
@hosts = {}
|
29
|
-
end
|
30
|
-
|
31
|
-
# Load the {Middleware::Proxy} application with the specified hosts.
|
32
|
-
def load_app
|
33
|
-
return Middleware::Proxy.new(Middleware::BadRequest, @hosts)
|
34
|
-
end
|
35
|
-
|
36
|
-
# The name of the controller which is used for the process title.
|
37
|
-
def name
|
38
|
-
"Falcon Proxy Server"
|
39
|
-
end
|
40
|
-
|
41
|
-
# Look up the host context for the given hostname, and update the socket hostname if necessary.
|
42
|
-
# @parameter socket [OpenSSL::SSL::SSLSocket] The incoming connection.
|
43
|
-
# @parameter hostname [String] The negotiated hostname.
|
44
|
-
def host_context(socket, hostname)
|
45
|
-
if host = @hosts[hostname]
|
46
|
-
Console.logger.debug(self) {"Resolving #{hostname} -> #{host}"}
|
47
|
-
|
48
|
-
socket.hostname = hostname
|
49
|
-
|
50
|
-
return host.ssl_context
|
51
|
-
else
|
52
|
-
Console.logger.warn(self) {"Unable to resolve #{hostname}!"}
|
53
|
-
|
54
|
-
return nil
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
# Generate an SSL context which delegates to {host_context} to multiplex based on hostname.
|
59
|
-
def ssl_context
|
60
|
-
@server_context ||= OpenSSL::SSL::SSLContext.new.tap do |context|
|
61
|
-
context.servername_cb = Proc.new do |socket, hostname|
|
62
|
-
self.host_context(socket, hostname)
|
63
|
-
end
|
64
|
-
|
65
|
-
context.session_id_context = @session_id
|
66
|
-
|
67
|
-
context.ssl_version = :TLSv1_2_server
|
68
|
-
|
69
|
-
context.set_params(
|
70
|
-
ciphers: TLS::SERVER_CIPHERS,
|
71
|
-
verify_mode: OpenSSL::SSL::VERIFY_NONE,
|
72
|
-
)
|
73
|
-
|
74
|
-
context.setup
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
# The endpoint the server will bind to.
|
79
|
-
def endpoint
|
80
|
-
@command.endpoint.with(
|
81
|
-
ssl_context: self.ssl_context,
|
82
|
-
reuse_address: true,
|
83
|
-
)
|
84
|
-
end
|
85
|
-
|
86
|
-
# Builds a map of host redirections.
|
87
|
-
def start
|
88
|
-
configuration = @command.configuration
|
89
|
-
|
90
|
-
services = Services.new(configuration)
|
91
|
-
|
92
|
-
@hosts = {}
|
93
|
-
|
94
|
-
services.each do |service|
|
95
|
-
if service.is_a?(Service::Proxy)
|
96
|
-
Console.logger.info(self) {"Proxying #{service.authority} to #{service.endpoint}"}
|
97
|
-
@hosts[service.authority] = service
|
98
|
-
|
99
|
-
# Pre-cache the ssl contexts:
|
100
|
-
# It seems some OpenSSL objects don't like event-driven I/O.
|
101
|
-
service.ssl_context
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
super
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
@@ -1,59 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Released under the MIT License.
|
4
|
-
# Copyright, 2020-2023, by Samuel Williams.
|
5
|
-
|
6
|
-
require 'async/container/controller'
|
7
|
-
|
8
|
-
require_relative 'serve'
|
9
|
-
require_relative '../middleware/redirect'
|
10
|
-
require_relative '../service/proxy'
|
11
|
-
|
12
|
-
module Falcon
|
13
|
-
module Controller
|
14
|
-
# A controller for redirecting requests.
|
15
|
-
class Redirect < Serve
|
16
|
-
# Initialize the redirect controller.
|
17
|
-
# @parameter command [Command::Redirect] The user-specified command-line options.
|
18
|
-
def initialize(command, **options)
|
19
|
-
super(command, **options)
|
20
|
-
|
21
|
-
@hosts = {}
|
22
|
-
end
|
23
|
-
|
24
|
-
# Load the {Middleware::Redirect} application with the specified hosts.
|
25
|
-
def load_app
|
26
|
-
return Middleware::Redirect.new(Middleware::NotFound, @hosts, @command.redirect_endpoint)
|
27
|
-
end
|
28
|
-
|
29
|
-
# The name of the controller which is used for the process title.
|
30
|
-
def name
|
31
|
-
"Falcon Redirect Server"
|
32
|
-
end
|
33
|
-
|
34
|
-
# The endpoint the server will bind to.
|
35
|
-
def endpoint
|
36
|
-
@command.endpoint.with(
|
37
|
-
reuse_address: true,
|
38
|
-
)
|
39
|
-
end
|
40
|
-
|
41
|
-
# Builds a map of host redirections.
|
42
|
-
def start
|
43
|
-
configuration = @command.configuration
|
44
|
-
|
45
|
-
services = Services.new(configuration)
|
46
|
-
|
47
|
-
@hosts = {}
|
48
|
-
|
49
|
-
services.each do |service|
|
50
|
-
if service.is_a?(Service::Proxy)
|
51
|
-
@hosts[service.authority] = service
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
super
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
@@ -1,110 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Released under the MIT License.
|
4
|
-
# Copyright, 2020-2023, by Samuel Williams.
|
5
|
-
# Copyright, 2020, by Michael Adams.
|
6
|
-
|
7
|
-
require_relative '../server'
|
8
|
-
|
9
|
-
require 'async/container/controller'
|
10
|
-
require 'async/io/trap'
|
11
|
-
|
12
|
-
require 'async/io/shared_endpoint'
|
13
|
-
|
14
|
-
module Falcon
|
15
|
-
module Controller
|
16
|
-
# A generic controller for serving an application.
|
17
|
-
# Uses {Server} for handling incoming requests.
|
18
|
-
class Serve < Async::Container::Controller
|
19
|
-
# Initialize the server controller.
|
20
|
-
# @parameter command [Command::Serve] The user-specified command-line options.
|
21
|
-
def initialize(command, **options)
|
22
|
-
@command = command
|
23
|
-
|
24
|
-
@endpoint = nil
|
25
|
-
@bound_endpoint = nil
|
26
|
-
@debug_trap = Async::IO::Trap.new(:USR1)
|
27
|
-
|
28
|
-
super(**options)
|
29
|
-
end
|
30
|
-
|
31
|
-
# Create the controller as specified by the command.
|
32
|
-
# e.g. `Async::Container::Forked`.
|
33
|
-
def create_container
|
34
|
-
@command.container_class.new
|
35
|
-
end
|
36
|
-
|
37
|
-
# The endpoint the server will bind to.
|
38
|
-
def endpoint
|
39
|
-
@command.endpoint
|
40
|
-
end
|
41
|
-
|
42
|
-
# @returns [Protocol::HTTP::Middleware] an instance of the application to be served.
|
43
|
-
def load_app
|
44
|
-
@command.load_app
|
45
|
-
end
|
46
|
-
|
47
|
-
# Prepare the bound endpoint for the server.
|
48
|
-
def start
|
49
|
-
@endpoint ||= self.endpoint
|
50
|
-
|
51
|
-
@bound_endpoint = Async do
|
52
|
-
Async::IO::SharedEndpoint.bound(@endpoint)
|
53
|
-
end.wait
|
54
|
-
|
55
|
-
Console.logger.info(self) { "Starting #{name} on #{@endpoint.to_url}" }
|
56
|
-
|
57
|
-
@debug_trap.ignore!
|
58
|
-
|
59
|
-
super
|
60
|
-
end
|
61
|
-
|
62
|
-
# The name of the controller which is used for the process title.
|
63
|
-
def name
|
64
|
-
"Falcon Server"
|
65
|
-
end
|
66
|
-
|
67
|
-
# Setup the container with the application instance.
|
68
|
-
# @parameter container [Async::Container::Generic]
|
69
|
-
def setup(container)
|
70
|
-
container.run(name: self.name, restart: true, **@command.container_options) do |instance|
|
71
|
-
Async do |task|
|
72
|
-
# Load one app instance per container:
|
73
|
-
app = self.load_app
|
74
|
-
|
75
|
-
task.async do
|
76
|
-
if @debug_trap.install!
|
77
|
-
Console.logger.info(instance) do
|
78
|
-
"- Per-process status: kill -USR1 #{Process.pid}"
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
@debug_trap.trap do
|
83
|
-
Console.logger.info(self) do |buffer|
|
84
|
-
task.reactor.print_hierarchy(buffer)
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
server = Falcon::Server.new(app, @bound_endpoint, protocol: @endpoint.protocol, scheme: @endpoint.scheme)
|
90
|
-
|
91
|
-
server.run
|
92
|
-
|
93
|
-
instance.ready!
|
94
|
-
|
95
|
-
task.children.each(&:wait)
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
# Close the bound endpoint.
|
101
|
-
def stop(*)
|
102
|
-
@bound_endpoint&.close
|
103
|
-
|
104
|
-
@debug_trap.default!
|
105
|
-
|
106
|
-
super
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
@@ -1,56 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Released under the MIT License.
|
4
|
-
# Copyright, 2019-2023, by Samuel Williams.
|
5
|
-
# Copyright, 2020, by Daniel Evans.
|
6
|
-
|
7
|
-
require_relative '../proxy_endpoint'
|
8
|
-
require_relative '../server'
|
9
|
-
|
10
|
-
require_relative '../service/application'
|
11
|
-
|
12
|
-
# A general application environment.
|
13
|
-
# Suitable for use with any {Protocol::HTTP::Middleware}.
|
14
|
-
#
|
15
|
-
# @scope Falcon Environments
|
16
|
-
# @name application
|
17
|
-
environment(:application) do
|
18
|
-
# The middleware stack for the application.
|
19
|
-
# @attribute [Protocol::HTTP::Middleware]
|
20
|
-
middleware do
|
21
|
-
::Protocol::HTTP::Middleware::HelloWorld
|
22
|
-
end
|
23
|
-
|
24
|
-
# The scheme to use to communicate with the application.
|
25
|
-
# @attribute [String]
|
26
|
-
scheme 'https'
|
27
|
-
|
28
|
-
# The protocol to use to communicate with the application.
|
29
|
-
#
|
30
|
-
# Typically one of {Async::HTTP::Protocol::HTTP1} or {Async::HTTP::Protocl::HTTP2}.
|
31
|
-
#
|
32
|
-
# @attribute [Async::HTTP::Protocol]
|
33
|
-
protocol {Async::HTTP::Protocol::HTTP2}
|
34
|
-
|
35
|
-
# The IPC path to use for communication with the application.
|
36
|
-
# @attribute [String]
|
37
|
-
ipc_path {::File.expand_path("application.ipc", root)}
|
38
|
-
|
39
|
-
# The endpoint that will be used for communicating with the application server.
|
40
|
-
# @attribute [Async::IO::Endpoint]
|
41
|
-
endpoint do
|
42
|
-
::Falcon::ProxyEndpoint.unix(ipc_path,
|
43
|
-
protocol: protocol,
|
44
|
-
scheme: scheme,
|
45
|
-
authority: authority
|
46
|
-
)
|
47
|
-
end
|
48
|
-
|
49
|
-
# The service class to use for the application.
|
50
|
-
# @attribute [Class]
|
51
|
-
service ::Falcon::Service::Application
|
52
|
-
|
53
|
-
# Number of instances to start.
|
54
|
-
# @attribute [Integer | nil]
|
55
|
-
count nil
|
56
|
-
end
|