Skip to content

Commit ce16dba

Browse files
Create a separate process with a single worker
- To handle service-to-service communication which must be kept HTTP/1.1 - Since only internal communication is possible we restrict allowed paths in requests to use the API only - /up is also included for healthchecking the process
1 parent 6a62bce commit ce16dba

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

falcon.rb

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,41 @@
3939
Async::HTTP::Endpoint.parse("#{scheme}://0.0.0.0:#{port}").with(**options)
4040
end
4141
end
42+
43+
if ENV["SERVICE_CONNECT_PORT"]
44+
service "#{hostname}-http" do
45+
include Falcon::Environment::Rack
46+
47+
preload "preload.rb"
48+
49+
count 1
50+
51+
protocol { Async::HTTP::Protocol::HTTP11 }
52+
scheme { "http" }
53+
54+
rack_app do
55+
app = super()
56+
allowed_paths = %w[/api/reporting/ /up]
57+
58+
->(env) do
59+
if allowed_paths.any? { |path| env["PATH_INFO"].start_with?(path) }
60+
app.call(env)
61+
else
62+
[
63+
403,
64+
{ "content-type" => "text/plain" },
65+
[
66+
"Path #{env["PATH_INFO"]} is not allowed. Allowed paths: #{allowed_paths.join(", ")}"
67+
]
68+
]
69+
end
70+
end
71+
end
72+
73+
endpoint do
74+
Async::HTTP::Endpoint.parse(
75+
"http://0.0.0.0:#{ENV["SERVICE_DIRECT_PORT"]}"
76+
).with(protocol: protocol)
77+
end
78+
end
79+
end

0 commit comments

Comments
 (0)