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:

  • .rb files are evaluated by Protocol::HTTP::Middleware.load using the protocol HTTP middleware builder interface.
  • .ru files 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

Instance Method Details

#configuration_pathObject

The explicitly specified application configuration path, if any.



31
32
33
# File 'lib/falcon/environment/serve.rb', line 31

def configuration_path
	nil
end

#middlewareObject

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_pathObject

Resolve the application configuration path.

Raises:

  • (ArgumentError)


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.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