Skip to content

Commit 721cac6

Browse files
committed
Add initial agent context.
1 parent fa80299 commit 721cac6

File tree

4 files changed

+177
-0
lines changed

4 files changed

+177
-0
lines changed

context/deployment.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Deployment
2+
3+
This guide explains how to use Falcon in production environments.
4+
5+
Falcon can be deployed into production either as a standalone application server, or as a virtual host routing to multiple applications. Both configurations can run behind a load balancer, but `falcon virtual` is designed to be zero-configuration deployment option.
6+
7+
## Falcon Serve
8+
9+
`falcon serve` is not designed for deployment because the command line interface is not guaranteed to be stable nor does it expose every possible configuration option.
10+
11+
## Falcon Hosts
12+
13+
`falcon host` is designed for deployment, and is the recommended way to deploy Falcon in production. It exposes a well defined interface for configuring services (web applications, job servers, etc).
14+
15+
### Configuration
16+
17+
`falcon host` loads configuration from the `falcon.rb` file in your application directory. This file contains configuration blocks which define how to host the application and any related services. This file should be executable and it invokes `falcon-host` which starts all defined services.
18+
19+
Here is a basic example which hosts a rack application using :
20+
21+
~~~ ruby
22+
#!/usr/bin/env falcon-host
23+
# frozen_string_literal: true
24+
25+
require "falcon/environment/rack"
26+
require "falcon/environment/lets_encrypt_tls"
27+
require "falcon/environment/supervisor"
28+
29+
hostname = File.basename(__dir__)
30+
service hostname do
31+
include Falcon::Environment::Rack
32+
include Falcon::Environment::LetsEncryptTLS
33+
34+
# Insert an in-memory cache in front of the application (using async-http-cache).
35+
cache true
36+
end
37+
38+
service "supervisor" do
39+
include Falcon::Environment::Supervisor
40+
end
41+
~~~
42+
43+
These configuration blocks are evaluated using the [async-service](https://github.com/socketry/async-service) gem. The supervisor is an independent service which monitors the health of the application and can restart it if necessary. Other services like background job processors can be added to the configuration.
44+
45+
### Environments
46+
47+
The service blocks define configuration that is loaded by the serivce layer to control how the service is run. The `service ... do` block defines the service name and the environment in which it runs. Different modules can be included to provide different functionality, such as `Falcon::Environment::Rack` for Rack applications, or `Falcon::Environment::LetsEncryptTLS` for automatic TLS certificate management.
48+
49+
## Falcon Virtual
50+
51+
Falcon virtual provides a virtual host proxy and HTTP-to-HTTPS redirection for multiple applications. It is designed to be a zero-configuration deployment option, allowing you to run multiple applications on the same server.
52+
53+
You need to create a `falcon.rb` configuration in the root of your applications, and start the virtual host:
54+
55+
~~~ bash
56+
falcon virtual /srv/http/*/falcon.rb
57+
~~~
58+
59+
See the [docker example](https://github.com/socketry/falcon-virtual-docker-example) for a complete working example.

context/rails.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Rails Integration
2+
3+
Falcon can serve Rails applications, however **it is highly recommended to use the latest stable release of Rails** for the best compatibility and performance. This guide explains how to host Rails applications with Falcon.
4+
5+
## Integration with Rails
6+
7+
Because Rails apps are built on top of Rack, they are compatible with Falcon.
8+
9+
1. Add `gem "falcon"` to your `Gemfile` and perhaps remove `gem "puma"` once you are satisfied with the change.
10+
2. Run `falcon serve` to start a local development server.
11+
12+
We do not recommend using Rails older than v7.1 with Falcon. If you are using an older version of Rails, you should upgrade to the latest version before using Falcon.
13+
14+
Falcon assumes HTTPS by default (so that browsers can use HTTP2). To run under HTTP in development you can bind it to an explicit scheme, host and port:
15+
16+
~~~ bash
17+
falcon serve -b http://localhost:3000
18+
~~~
19+
20+
## Isolation Level
21+
22+
Rails provides the ability to change its internal isolation level from threads (default) to fibers. When you use `falcon` with Rails, it will automatically set the isolation level to fibers.
23+
24+
## ActionCable
25+
26+
Falcon fully supports ActionCable with the [`Async::Cable` adapter](https://github.com/socketry/async-cable).
27+
28+
## ActiveJob
29+
30+
Falcon fully supports ActiveJob with the [`Async::Job` adapter](https://github.com/socketry/async-job-adapter-active_job).

context/streaming.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Streaming
2+
3+
Falcon supports streaming input and output, allowing you to send and receive data in real-time. This is particularly useful for applications that require live updates, such as chat applications or real-time dashboards.
4+
5+
## WebSockets
6+
7+
Falcon supports `Async::WebSocket` for client and server WebSocket connections. This allows for full-duplex communication channels over a single TCP connection, enabling real-time data exchange (including via HTTP/2).
8+
9+
```ruby
10+
require 'async/websocket/adapters/rack'
11+
require 'set'
12+
13+
run lambda {|env|
14+
Async::WebSocket::Adapters::Rack.open(env, protocols: ['ws']) do |connection|
15+
# Echo server:
16+
while message = connection.read
17+
connection.write(message)
18+
connection.flush
19+
end
20+
end or [404, {}, []]
21+
}
22+
```
23+
24+
25+
26+
## Server Sent Events
27+
28+
Falcon supports Server-Sent Events (SSE) for sending real-time updates to clients. This is useful for applications that need to push updates to the browser without requiring a full page reload.
29+
30+
```ruby
31+
def server_sent_events?(env)
32+
env['HTTP_ACCEPT'].include?('text/event-stream')
33+
end
34+
35+
run do |env|
36+
if server_sent_events?(env)
37+
body = proc do |stream|
38+
while true
39+
stream << "data: The time is #{Time.now}\n\n"
40+
sleep 1
41+
end
42+
rescue => error
43+
ensure
44+
stream.close(error)
45+
end
46+
47+
[200, {'content-type' => 'text/event-stream'}, body]
48+
else
49+
# Else the request is for the index page, return the contents of index.html:
50+
[200, {'content-type' => 'text/html'}, [File.read('index.html')]]
51+
end
52+
end
53+
```

context/usage.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Usage
2+
3+
Falcon is a high-performance web server designed for Ruby applications, particularly those that require efficient handling of both asynchronous I/O and CPU-bound tasks. This guide provides an overview of how to use Falcon effectively, especially in scenarios involving concurrent processing.
4+
5+
## Overview
6+
7+
Falcon operates by creating a server that can handle multiple requests concurrently, leveraging Ruby's async capabilities. It is built on top of the `async` gem and integrates with Rack applications, allowing for seamless handling of web requests.
8+
9+
## Rack Support
10+
11+
Falcon supports traditional Rack applications, enabling developers to run existing Ruby web frameworks (like Sinatra or Rails) with minimal changes. It wraps the incoming HTTP requests and responses, allowing for a consistent interface across different types of applications.
12+
13+
```
14+
# config.ru
15+
16+
run do |env|
17+
[200, { 'Content-Type' => 'text/plain' }, ['Hello from Falcon!']]
18+
end
19+
```
20+
21+
You can run this application using Falcon by executing:
22+
23+
```bash
24+
falcon serve
25+
```
26+
27+
Falcon itself supports HTTP/2 by default, which requires the use of TLS. To do this, it uses the `localhost` gem which creates self-signed certificates for local development.
28+
29+
### Un-encrypted HTTP
30+
31+
Falcon can also run unencrypted HTTP for development purposes. To do this, you can specify the `--bind` option when starting the server:
32+
33+
```bash
34+
falcon serve --bind http://localhost:9292
35+
```

0 commit comments

Comments
 (0)