Skip to content

Commit

Permalink
Heroku example for the Deployment Guide (#235)
Browse files Browse the repository at this point in the history
  • Loading branch information
trevorturk authored Apr 16, 2024
1 parent 93b113c commit 3fad7ef
Showing 1 changed file with 47 additions and 2 deletions.
49 changes: 47 additions & 2 deletions guides/deployment/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ hostname = File.basename(__dir__)
service hostname do
include Falcon::Environment::Rack
include Falcon::Environment::LetsEncryptTLS

# Insert an in-memory cache in front of the application (using async-http-cache).
cache true
end
Expand All @@ -50,7 +50,7 @@ hostname = File.basename(__dir__)
service hostname do
include Falcon::Environment::Rack
include Falcon::Environment::LetsEncryptTLS

endpoint do
Async::HTTP::Endpoint.parse('http://localhost:3000').with(protocol: Async::HTTP::Protocol::HTTP2)
end
Expand All @@ -63,6 +63,51 @@ end

You can verify this is working using `nghttp -v http://localhost:3000`.

#### Application Configuration Example for Heroku

Building on the examples above, the following is a full configuration example for Heroku:

~~~ bash
# Procfile

web: bundle exec falcon host
~~~

~~~ ruby
# falcon.rb

#!/usr/bin/env -S falcon host

load :rack

hostname = File.basename(__dir__)
port = ENV["PORT"] || 3000

service hostname do
include Falcon::Environment::Rack

# By default, Falcon uses Etc.nprocessors to set the count, which is likely incorrect on shared hosts like Heroku.
# Review the following for guidance about how to find the right value for your app:
# https://help.heroku.com/88G3XLA6/what-is-an-acceptable-amount-of-dyno-load
# https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server#workers
count ENV.fetch("WEB_CONCURRENCY", 1).to_i

# If using count > 1 you may want to preload your app to reduce memory usage and increase performance:
preload "preload.rb"

# Heroku only supports HTTP/1.1 at the time of this writing. Review the following for possible updates in the future:
# https://devcenter.heroku.com/articles/http-routing#http-versions-supported
# https://github.com/heroku/roadmap/issues/34
endpoint Async::HTTP::Endpoint.parse("http://0.0.0.0:#{port}").with(protocol: Async::HTTP::Protocol::HTTP11)
end
~~~

~~~ ruby
# preload.rb

require_relative "config/environment"
~~~

## Falcon Virtual

Falcon can replace Nginx as a virtual server for Ruby applications.
Expand Down

0 comments on commit 3fad7ef

Please sign in to comment.