You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: context/how-it-works.md
+10Lines changed: 10 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,6 +8,16 @@ When you run `falcon serve`, Falcon creates a {ruby Falcon::Controller::Serve} w
8
8
9
9
The workers individually load a copy of your rack application. These applications are wrapped using {ruby Falcon::Adapters::Rack} which modifies the incoming {ruby Protocol::HTTP::Request} object into an `env` object suitable for your application. It also handles converting the output of your rack application `[status, headers, body]` into an instance of {ruby Falcon::Adapters::Response} which is derived from {ruby Protocol::HTTP::Response}.
10
10
11
+
See the [protocol-http documentation](https://socketry.github.io/protocol-http/) for more details on how it works.
12
+
11
13
## Server
12
14
13
15
The server itself is mostly implemented by {ruby Async::HTTP::Server} which in turn depends on the `protocol-http` gems for the actual protocol implementations. Therefore, Falcon is primarily a bridge between the underlying protocol objects and the Rack interface.
16
+
17
+
See the [async-http documentation](https://socketry.github.io/async-http/) for more details on how it works.
18
+
19
+
## Protocol::Rack
20
+
21
+
Falcon uses the `protocol-rack` gem to provide a Rack interface for the HTTP protocol. This allows you to run any Rack-compatible application with Falcon. However, Falcon itself is not a Rack server, but rather an HTTP server that can run Rack applications.
22
+
23
+
See the [protocol-rack documentation](https://socketry.github.io/protocol-rack/) for more details on how it works.
This guide explains how to use interim responses in Falcon to send early hints to the client.
4
+
5
+
## Overview
6
+
7
+
Interim responses allow the server to send early hints to the client before the final response is ready. This can be useful for preloading resources or providing immediate feedback. They can also be used as a response to the `expect` header, allowing the server to indicate that it is ready to process the request without waiting for the full request body.
8
+
9
+
Since Rack does not currently have a specificatio for interim responses, you need to access the underlying HTTP response object directly.
This guide explains how to use interim responses in Falcon to send early hints to the client.
4
+
5
+
## Overview
6
+
7
+
Interim responses allow the server to send early hints to the client before the final response is ready. This can be useful for preloading resources or providing immediate feedback. They can also be used as a response to the `expect` header, allowing the server to indicate that it is ready to process the request without waiting for the full request body.
8
+
9
+
Since Rack does not currently have a specificatio for interim responses, you need to access the underlying HTTP response object directly.
Copy file name to clipboardExpand all lines: context/rails-integration.md
+33-18Lines changed: 33 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,31 +2,47 @@
2
2
3
3
This guide explains how to host Rails applications with Falcon.
4
4
5
-
**We strongly recommend using the latest stable release of Rails with Falcon.** The integration is much smoother and you will benefit from the latest features and bug fixes. This guide is primarily intended for users of Rails 8.0 and later.
5
+
**We strongly recommend using the latest stable release of Rails with Falcon.**
6
6
7
-
## Integration with Rails
7
+
We now recommend using the `Falcon::Rails` gem for Rails integration. This gem provides a simple way to configure Falcon as the web server for your Rails application, and includes many conveniences for running Rails with Falcon.
8
+
9
+
~~~
10
+
> bundle add falcon-rails
11
+
~~~
12
+
13
+
It also includes detailed documentation for [common tasks and configurations](https://socketry.github.io/falcon-rails/).
14
+
15
+
## Usage
8
16
9
17
Because Rails apps are built on top of Rack, they are compatible with Falcon.
10
18
11
19
1. Add `gem "falcon"` to your `Gemfile` and perhaps remove `gem "puma"` once you are satisfied with the change.
12
20
2. Run `falcon serve` to start a local development server.
13
21
14
-
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.
15
-
16
22
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:
17
23
18
24
~~~bash
19
25
falcon serve -b http://localhost:3000
20
26
~~~
21
27
28
+
### Self-signed Development Certificates
29
+
30
+
The [localhost gem](https://github.com/socketry/localhost) is used to generate self-signed certificates for local development. This allows you to run Falcon with HTTPS in development without needing to set up a real certificate authority. However, you must still install the development certificate to avoid security warnings in your browser:
31
+
32
+
~~~bash
33
+
> bundle exec bake localhost:install
34
+
~~~
35
+
22
36
### Production
23
37
24
-
The `falcon serve` command is only intended to be used for local development. Follow these steps to run a production Rails app with Falcon:
38
+
The `falcon serve` command is only intended to be used for local development. We recommend you use `falcon host` for production deployments.
25
39
26
-
1. Create a `falcon.rb` file
40
+
#### Falcon Host Configuration File
41
+
42
+
Create a `falcon.rb` file in the root of your Rails application. This file will be used to configure the Falcon server for production. The following example binds HTTP/1 to port 3000 as is common for Rails applications:
27
43
28
44
~~~ruby
29
-
#!/usr/bin/env -S falconhost
45
+
#!/usr/bin/env -S falcon-host
30
46
# frozen_string_literal: true
31
47
32
48
require"falcon/environment/rack"
@@ -51,25 +67,24 @@ service hostname do
51
67
end
52
68
~~~
53
69
54
-
2. Create a `preload.rb` file
70
+
#### Preloading Rails
71
+
72
+
Preloading is a technique used to load your Rails application into memory before forking worker processes. This can significantly improve performance by reducing the time it takes to start each worker.
55
73
56
74
~~~ruby
57
75
# frozen_string_literal: true
58
76
59
77
require_relative"config/environment"
60
78
~~~
61
79
62
-
3. Run the production server with `bundle exec falcon host`
63
-
64
-
65
-
## Isolation Level
80
+
#### Running the Production Server
66
81
67
-
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.
82
+
To run the production server, make sure your `falcon.rb` is executable and then run it:
68
83
69
-
## ActionCable
70
-
71
-
Falcon fully supports ActionCable with the [`Async::Cable` adapter](https://github.com/socketry/async-cable).
84
+
~~~bash
85
+
> bundle exec falcon.rb
86
+
~~~
72
87
73
-
## ActiveJob
88
+
## Isolation Level
74
89
75
-
Falcon fully supports ActiveJob with the [`Async::Job` adapter](https://github.com/socketry/async-job-adapter-active_job).
90
+
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 as Falcon provides the appropriate Railtie.
This guide explains how to use WebSockets with Falcon.
4
+
5
+
## Overview
6
+
7
+
Falcon supports WebSockets using the [async-websocket gem](https://github.com/socketry/async-websocket). This allows you to build real-time applications that can handle bidirectional communication between the server and clients.
8
+
9
+
~~~ruby
10
+
# config.ru
11
+
12
+
require"async/websocket/adapter/rack"
13
+
14
+
run do |env|
15
+
Async::WebSocket::Adapters::Rack.open(env, protocols: ['ws']) do |connection|
Copy file name to clipboardExpand all lines: guides/how-it-works/readme.md
+10Lines changed: 10 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,6 +8,16 @@ When you run `falcon serve`, Falcon creates a {ruby Falcon::Controller::Serve} w
8
8
9
9
The workers individually load a copy of your rack application. These applications are wrapped using {ruby Falcon::Adapters::Rack} which modifies the incoming {ruby Protocol::HTTP::Request} object into an `env` object suitable for your application. It also handles converting the output of your rack application `[status, headers, body]` into an instance of {ruby Falcon::Adapters::Response} which is derived from {ruby Protocol::HTTP::Response}.
10
10
11
+
See the [protocol-http documentation](https://socketry.github.io/protocol-http/) for more details on how it works.
12
+
11
13
## Server
12
14
13
15
The server itself is mostly implemented by {ruby Async::HTTP::Server} which in turn depends on the `protocol-http` gems for the actual protocol implementations. Therefore, Falcon is primarily a bridge between the underlying protocol objects and the Rack interface.
16
+
17
+
See the [async-http documentation](https://socketry.github.io/async-http/) for more details on how it works.
18
+
19
+
## Protocol::Rack
20
+
21
+
Falcon uses the `protocol-rack` gem to provide a Rack interface for the HTTP protocol. This allows you to run any Rack-compatible application with Falcon. However, Falcon itself is not a Rack server, but rather an HTTP server that can run Rack applications.
22
+
23
+
See the [protocol-rack documentation](https://socketry.github.io/protocol-rack/) for more details on how it works.
This guide explains how to use interim responses in Falcon to send early hints to the client.
4
+
5
+
## Overview
6
+
7
+
Interim responses allow the server to send early hints to the client before the final response is ready. This can be useful for preloading resources or providing immediate feedback. They can also be used as a response to the `expect` header, allowing the server to indicate that it is ready to process the request without waiting for the full request body.
8
+
9
+
Since Rack does not currently have a specificatio for interim responses, you need to access the underlying HTTP response object directly.
0 commit comments