module Serve
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 byProtocol::HTTP::Middleware.loadusing the protocol HTTP middleware builder interface..rufiles are parsed as Rack applications and wrapped withProtocol::Rack::Adapter.
Both application interfaces respond to call, so the configuration file
extension is the explicit contract rather than inspecting the loaded object.
Definitions
def configuration_path
The explicitly specified application configuration path, if any.
Signature
-
returns
String | Nil
Implementation
def configuration_path
nil
end
def resolved_configuration_path
Resolve the application configuration path.
Signature
-
returns
String The absolute application configuration path.
Implementation
def resolved_configuration_path
if configuration_path
return File.expand_path(configuration_path, root)
end
serve_path = File.expand_path("config/serve.rb", root)
if File.file?(serve_path)
return serve_path
end
rackup_path = File.expand_path("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
def middleware
Load and wrap the configured application.
Signature
-
returns
Protocol::HTTP::Middleware The middleware stack.
Implementation
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