Class: Rage::Configuration
- Inherits:
-
Object
- Object
- Rage::Configuration
- Defined in:
- lib/rage/configuration.rb
Overview
Rage.configure
can be used to adjust the behavior of your Rage application:
Rage.configure do
config.logger = Rage::Logger.new(STDOUT)
config.server.workers_count = 2
end
General Configuration
• config.logger
The logger that will be used for
Rage.logger
and any relatedRage
logging. Custom loggers should implement Ruby’s Logger interface.
• config.log_formatter
The formatter of the Rage logger. Built in options include
Rage::TextFormatter
andRage::JSONFormatter
. Defaults to an instance ofRage::TextFormatter
.
• config.log_level
Defines the verbosity of the Rage logger. This option defaults to
:debug
for all environments except production, where it defaults to:info
. The available log levels are::debug
,:info
,:warn
,:error
,:fatal
, and:unknown
.
• config.secret_key_base
The
secret_key_base
is used as the input secret to the application’s key generator, which is used to encrypt cookies. Rage will fall back to theSECRET_KEY_BASE
environment variable if this is not set.
• config.fallback_secret_key_base
Defines one or several old secrets that need to be rotated. Can accept a single key or an array of keys. Rage will fall back to the
FALLBACK_SECRET_KEY_BASE
environment variable if this is not set.
Middleware Configuration
• config.middleware.use
Adds a middleware to the top of the middleware stack. This is the recommended way of adding a middleware.
config.middleware.use Rack::Cors do allow do origins "*" resource "*", headers: :any end end
• config.middleware.insert_before
Adds middleware at a specified position before another middleware. The position can be either an index or another middleware.
❗️Heads up: By default, Rage always uses the
Rage::FiberWrapper
middleware, which wraps every request in a separate fiber. Make sure to always have this middleware in the top of the stack. Placing other middlewares in front may lead to undefined behavior.config.middleware.insert_before Rack::Head, Magical::Unicorns config.middleware.insert_before 0, Magical::Unicorns
• config.middleware.insert_after
Adds middleware at a specified position after another middleware. The position can be either an index or another middleware.
config.middleware.insert_after Rack::Head, Magical::Unicorns
Server Configuration
• config.server.max_clients
Limits the number of simultaneous connections the server can accept. Defaults to the maximum number of open files.
❗️Heads up: Decreasing this number is almost never a good idea. Depending on your application specifics, you are encouraged to use other methods to limit the number of concurrent connections:
If your application is exposed to the public, you may want to use a cloud rate limiter, like Cloudflare WAF or Fastly WAF.
Otherwise, consider using tools like Rack::Attack or connection_pool.
# Limit the amount of connections your application can accept config.middleware.use Rack::Attack Rack::Attack.throttle("req/ip", limit: 300, period: 5.minutes) do |req| req.ip end # # Limit the amount of connections to a specific resource HTTP = ConnectionPool.new(size: 5, timeout: 5) { Net::HTTP } HTTP.with do |conn| conn.get("/my-resource") end
• config.server.port
Specifies what port the server will listen on.
• config.server.workers_count
Specifies the number of server processes to run. Defaults to 1 in development and to the number of available CPU cores in other environments.
• config.server.timeout
Specifies connection timeout.
Static file server
• config.public_file_server.enabled
Configures whether Rage should serve static files from the public directory. Defaults to
false
.
Cable Configuration
• config.cable.protocol
Specifies the protocol the server will use. The only value currently supported is
Rage::Cable::Protocol::ActioncableV1Json
. The client application will need to use @rails/actioncable to talk to the server.
• config.cable.allowed_request_origins
Restricts the server to only accept requests from specified origins. The origins can be instances of strings or regular expressions, against which a check for the match will be performed.
• config.cable.disable_request_forgery_protection
Allows requests from any origin.
Transient Settings
The settings described in this section should be configured using environment variables and are either temporary or will become the default in the future.
• RAGE_DISABLE_IO_WRITE
Disables the
io_write
hook to fix the “zero-length iov” error on Ruby < 3.3.
• RAGE_DISABLE_AR_POOL_PATCH
Disables the
ActiveRecord::ConnectionPool
patch and makes Rage use the original ActiveRecord implementation.
• RAGE_DISABLE_AR_WEAK_CONNECTIONS
Instructs Rage to not reuse Active Record connections between different fibers.
Defined Under Namespace
Classes: Cable, Middleware, PublicFileServer, Server
Instance Attribute Summary collapse
- #fallback_secret_key_base ⇒ Object
-
#log_formatter ⇒ Object
Returns the value of attribute log_formatter.
-
#log_level ⇒ Object
Returns the value of attribute log_level.
-
#logger ⇒ Object
Returns the value of attribute logger.
- #secret_key_base ⇒ Object
Instance Method Summary collapse
- #cable ⇒ Object
-
#config ⇒ Object
used in DSL.
- #internal ⇒ Object
- #middleware ⇒ Object
- #public_file_server ⇒ Object
- #server ⇒ Object
Instance Attribute Details
#fallback_secret_key_base ⇒ Object
162 163 164 |
# File 'lib/rage/configuration.rb', line 162 def fallback_secret_key_base Array(@fallback_secret_key_base || ENV["FALLBACK_SECRET_KEY_BASE"]) end |
#log_formatter ⇒ Object
Returns the value of attribute log_formatter.
143 144 145 |
# File 'lib/rage/configuration.rb', line 143 def log_formatter @log_formatter end |
#log_level ⇒ Object
Returns the value of attribute log_level.
143 144 145 |
# File 'lib/rage/configuration.rb', line 143 def log_level @log_level end |
#logger ⇒ Object
Returns the value of attribute logger.
142 143 144 |
# File 'lib/rage/configuration.rb', line 142 def logger @logger end |
#secret_key_base ⇒ Object
158 159 160 |
# File 'lib/rage/configuration.rb', line 158 def secret_key_base @secret_key_base || ENV["SECRET_KEY_BASE"] end |
Instance Method Details
#cable ⇒ Object
174 175 176 |
# File 'lib/rage/configuration.rb', line 174 def cable @cable ||= Cable.new end |
#config ⇒ Object
used in DSL
147 |
# File 'lib/rage/configuration.rb', line 147 def config = self |
#internal ⇒ Object
182 183 184 |
# File 'lib/rage/configuration.rb', line 182 def internal @internal ||= Internal.new end |
#middleware ⇒ Object
170 171 172 |
# File 'lib/rage/configuration.rb', line 170 def middleware @middleware ||= Middleware.new end |
#public_file_server ⇒ Object
178 179 180 |
# File 'lib/rage/configuration.rb', line 178 def public_file_server @public_file_server ||= PublicFileServer.new end |