Skip to content

Commit 106e348

Browse files
committed
Add proxy example.
1 parent eeda3e7 commit 106e348

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

examples/proxy/application.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env falcon-host
2+
# frozen_string_literal: true
3+
4+
# Released under the MIT License.
5+
# Copyright, 2024, by Samuel Williams.
6+
7+
require 'async/http/client'
8+
9+
class Application
10+
# The endpoint we will proxy requests to:
11+
DEFAULT_PROXY_ENDPOINT = Async::HTTP::Endpoint.parse("http://localhost:3000")
12+
13+
def initialize(endpoint = DEFAULT_PROXY_ENDPOINT)
14+
@client = Async::HTTP::Client.new(endpoint)
15+
end
16+
17+
def call(request)
18+
@client.call(request)
19+
end
20+
end

examples/proxy/falcon.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env falcon-host
2+
# frozen_string_literal: true
3+
4+
# Released under the MIT License.
5+
# Copyright, 2024, by Samuel Williams.
6+
7+
require "falcon/environment/self_signed_tls"
8+
require "falcon/environment/rack"
9+
require "falcon/environment/supervisor"
10+
11+
require_relative "application"
12+
13+
service "proxy.localhost" do
14+
include Falcon::Environment::Application
15+
16+
scheme "http"
17+
protocol {Async::HTTP::Protocol::HTTP}
18+
19+
middleware do
20+
Application.new
21+
end
22+
23+
endpoint do
24+
Async::HTTP::Endpoint.for(scheme, "localhost", port: 9292, protocol: protocol)
25+
end
26+
end

0 commit comments

Comments
 (0)