mirror of
https://github.com/puma/puma.git
synced 2022-11-09 13:48:40 -05:00
Advertise the Configuration object for apps to use.
This commit is contained in:
parent
40af41e5ef
commit
211aef1589
3 changed files with 29 additions and 1 deletions
|
@ -327,6 +327,10 @@ module Puma
|
|||
end
|
||||
|
||||
@config = Puma::Configuration.new @options
|
||||
|
||||
# Advertise the Configuration
|
||||
Puma.cli_config = @config
|
||||
|
||||
@config.load
|
||||
end
|
||||
|
||||
|
|
|
@ -1,4 +1,14 @@
|
|||
module Puma
|
||||
|
||||
# The CLI exports it's Configuration object here to allow
|
||||
# apps to pick it up. An app needs to use it conditionally though
|
||||
# since it is not set if the app is launched via another
|
||||
# mechanism than the CLI class.
|
||||
|
||||
class << self
|
||||
attr_accessor :cli_config
|
||||
end
|
||||
|
||||
class Configuration
|
||||
DefaultRackup = "config.ru"
|
||||
|
||||
|
@ -44,6 +54,19 @@ module Puma
|
|||
end
|
||||
end
|
||||
|
||||
# Injects the Configuration object into the env
|
||||
class ConfigMiddleware
|
||||
def initialize(config, app)
|
||||
@config = config
|
||||
@app = app
|
||||
end
|
||||
|
||||
def call(env)
|
||||
env[Const::PUMA_CONFIG] = @config
|
||||
@app.call(env)
|
||||
end
|
||||
end
|
||||
|
||||
# Load the specified rackup file, pull an options from
|
||||
# the rackup file, and set @app.
|
||||
#
|
||||
|
@ -72,7 +95,7 @@ module Puma
|
|||
app = Rack::CommonLogger.new(app, logger)
|
||||
end
|
||||
|
||||
return app
|
||||
return ConfigMiddleware.new(self, app)
|
||||
end
|
||||
|
||||
def setup_random_token
|
||||
|
|
|
@ -119,6 +119,7 @@ module Puma
|
|||
RACK_URL_SCHEME = "rack.url_scheme".freeze
|
||||
RACK_AFTER_REPLY = "rack.after_reply".freeze
|
||||
PUMA_SOCKET = "puma.socket".freeze
|
||||
PUMA_CONFIG = "puma.config".freeze
|
||||
|
||||
HTTP = "http".freeze
|
||||
HTTPS = "https".freeze
|
||||
|
|
Loading…
Add table
Reference in a new issue