Class: Rage::Configuration
- Inherits:
-
Object
- Object
- Rage::Configuration
- Defined in:
- lib/rage/configuration.rb
Overview
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.
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_PATCH_AR_POOL
Enables the
ActiveRecord::ConnectionPool
patch to optimize database connection management. Use it to increase throughput under high load.
Defined Under Namespace
Classes: Middleware, 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
Instance Attribute Details
#fallback_secret_key_base ⇒ Object
129 130 131 |
# File 'lib/rage/configuration.rb', line 129 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.
110 111 112 |
# File 'lib/rage/configuration.rb', line 110 def log_formatter @log_formatter end |
#log_level ⇒ Object
Returns the value of attribute log_level.
110 111 112 |
# File 'lib/rage/configuration.rb', line 110 def log_level @log_level end |
#logger ⇒ Object
Returns the value of attribute logger.
109 110 111 |
# File 'lib/rage/configuration.rb', line 109 def logger @logger end |
#secret_key_base ⇒ Object
125 126 127 |
# File 'lib/rage/configuration.rb', line 125 def secret_key_base @secret_key_base || ENV["SECRET_KEY_BASE"] end |
Instance Method Details
#config ⇒ Object
used in DSL
114 |
# File 'lib/rage/configuration.rb', line 114 def config = self |
#internal ⇒ Object
141 142 143 |
# File 'lib/rage/configuration.rb', line 141 def internal @internal ||= Internal.new end |
#middleware ⇒ Object
137 138 139 |
# File 'lib/rage/configuration.rb', line 137 def middleware @middleware ||= Middleware.new end |