Module: Falcon::Environment::Serve
- Defined in:
- lib/falcon/environment/serve.rb
Overview
Provides application configuration discovery and loading for falcon serve.
When #configuration_path is nil, #resolved_configuration_path looks for
config/serve.rb first and falls back to config.ru. An explicit
#configuration_path bypasses this discovery order.
The file extension selects the application interface:
.rbfiles are evaluated by Protocol::HTTP::Middleware.load using the protocol HTTP middleware builder interface..rufiles are parsed as Rack applications and wrapped with Protocol::Rack::Adapter.
Both application interfaces respond to call, so the configuration file
extension is the explicit contract rather than inspecting the loaded object.
Instance Method Summary collapse
-
#configuration_path ⇒ Object
The explicitly specified application configuration path, if any.
-
#middleware ⇒ Object
Load and wrap the configured application.
-
#resolved_configuration_path ⇒ Object
Resolve the application configuration path.
Instance Method Details
#configuration_path ⇒ Object
The explicitly specified application configuration path, if any.
31 32 33 |
# File 'lib/falcon/environment/serve.rb', line 31 def configuration_path nil end |
#middleware ⇒ Object
Load and wrap the configured application.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/falcon/environment/serve.rb', line 57 def middleware path = resolved_configuration_path case File.extname(path) when ".rb" application = ::Protocol::HTTP::Middleware.load(path) return ::Falcon::Server.protocol_middleware(application, verbose: verbose, cache: cache) when ".ru" application = ::Protocol::Rack::Adapter.parse_file(path) return ::Falcon::Server.rack_middleware(application, verbose: verbose, cache: cache) else raise ArgumentError, "Unsupported application configuration: #{path}!" end end |
#resolved_configuration_path ⇒ Object
Resolve the application configuration path.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/falcon/environment/serve.rb', line 37 def resolved_configuration_path if configuration_path return File.(configuration_path, root) end serve_path = File.("config/serve.rb", root) if File.file?(serve_path) return serve_path end rackup_path = File.("config.ru", root) if File.file?(rackup_path) return rackup_path end raise ArgumentError, "Could not find config/serve.rb or config.ru in #{root}!" end |