{"record":{"id":"0aba9e7ef13b53da","repo":"socketry/falcon","slug":"could-not-find-config-serve-rb-or-config-ru-in-r","errorCode":null,"errorMessage":"Could not find config/serve.rb or config.ru in #{root}!","messagePattern":"Could not find config/serve\\.rb or config\\.ru in #(.+?)!","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/falcon/environment/serve.rb","lineNumber":52,"sourceCode":"\t\t\t\n\t\t\t# Resolve the application configuration path.\n\t\t\t# @returns [String] The absolute application configuration path.\n\t\t\tdef resolved_configuration_path\n\t\t\t\tif configuration_path\n\t\t\t\t\treturn File.expand_path(configuration_path, root)\n\t\t\t\tend\n\t\t\t\t\n\t\t\t\tserve_path = File.expand_path(\"config/serve.rb\", root)\n\t\t\t\tif File.file?(serve_path)\n\t\t\t\t\treturn serve_path\n\t\t\t\tend\n\t\t\t\t\n\t\t\t\trackup_path = File.expand_path(\"config.ru\", root)\n\t\t\t\tif File.file?(rackup_path)\n\t\t\t\t\treturn rackup_path\n\t\t\t\tend\n\t\t\t\t\n\t\t\t\traise ArgumentError, \"Could not find config/serve.rb or config.ru in #{root}!\"\n\t\t\tend\n\t\t\t\n\t\t\t# Load and wrap the configured application.\n\t\t\t# @returns [Protocol::HTTP::Middleware] The middleware stack.\n\t\t\tdef middleware\n\t\t\t\tpath = resolved_configuration_path\n\t\t\t\t\n\t\t\t\tcase File.extname(path)\n\t\t\t\twhen \".rb\"\n\t\t\t\t\tapplication = ::Protocol::HTTP::Middleware.load(path)\n\t\t\t\t\treturn ::Falcon::Server.protocol_middleware(application, verbose: verbose, cache: cache)\n\t\t\t\twhen \".ru\"\n\t\t\t\t\tapplication = ::Protocol::Rack::Adapter.parse_file(path)\n\t\t\t\t\treturn ::Falcon::Server.rack_middleware(application, verbose: verbose, cache: cache)\n\t\t\t\telse\n\t\t\t\t\traise ArgumentError, \"Unsupported application configuration: #{path}!\"\n\t\t\t\tend\n\t\t\tend","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/socketry/falcon/blob/5107b0713fd78dbe8b08ee123391b1f4bcffdf12/lib/falcon/environment/serve.rb#L34-L70","documentation":"Falcon's serve environment locates the application entry file by trying <root>/config/serve.rb and then <root>/config.ru whenever no explicit configuration_path is set (lib/falcon/environment/serve.rb:37-53). If both lookups miss, resolved_configuration_path raises ArgumentError naming the root it searched. Because middleware calls this resolver before anything loads, `falcon serve` aborts before any socket is bound, and the message tells you exactly which directory lacked the two files.","triggerScenarios":"Calling `falcon serve`, or Falcon::Environment::Serve#middleware / #resolved_configuration_path, when configuration_path returns nil and neither <root>/config/serve.rb nor <root>/config.ru exists — e.g. an empty project directory, a custom environment whose root resolves elsewhere, or a launcher (systemd, Docker, daemon) whose working directory is not the app root.","commonSituations":"Fresh project with no rackup file yet; running falcon from a subdirectory or under systemd/Docker where cwd differs from the app root; a config.ru living in a subfolder (apps/web/config.ru) while root points at the repo root; a custom environment that overrides root but leaves configuration_path nil.","solutions":["Create a minimal config.ru at the project root: run ->(env) { [200, {'content-type' => 'text/plain'}, ['ok']] }","Or create config/serve.rb to use the Protocol::HTTP middleware-builder interface instead of Rack","If the app file lives elsewhere, define configuration_path in your Falcon environment; it is expanded relative to root and bypasses discovery","Fix the working directory of the launching process (systemd WorkingDirectory, Docker WORKDIR) so root is the app root"],"exampleFix":"# before: falcon serve in a directory with neither config.ru nor config/serve.rb\n#   ArgumentError: Could not find config/serve.rb or config.ru in /srv/app!\n\n# after (option 1): create config.ru in the app root\n# config.ru\nrequire_relative 'config/application'\nrun MyApp\n\n# after (option 2): explicit path in the falcon environment\nclass MyAppEnvironment\n  include Falcon::Environment::Serve\n\n  def configuration_path\n    'apps/web/config.ru' # expanded relative to root; skips discovery\n  end\nend","handlingStrategy":"validation","validationCode":"# Run before starting falcon / calling environment.middleware\ndef falcon_config_available?(environment)\n  if (path = environment.configuration_path)\n    return File.file?(File.expand_path(path, environment.root))\n  end\n\n  %w[config/serve.rb config.ru].any? do |relative|\n    File.file?(File.expand_path(relative, environment.root))\n  end\nend\n\nunless falcon_config_available?(environment)\n  abort \"No config/serve.rb or config.ru under #{environment.root}; create one or set configuration_path\"\nend","typeGuard":null,"tryCatchPattern":"begin\n  middleware = environment.middleware\nrescue ArgumentError => error\n  abort \"falcon serve: #{error.message} (create config.ru or set configuration_path)\"\nend","preventionTips":["Keep a config.ru at the app root as the default entry point","Set configuration_path explicitly whenever the app file is not at <root>/config.ru or <root>/config/serve.rb","For systemd/Docker launches, set WorkingDirectory/WORKDIR to the app root and assert it in a preflight check","Add a File.file? assertion in the deploy pipeline before invoking falcon"],"tags":["falcon","rack","configuration","argument-error","file-not-found","ruby"],"backgroundTag":"missing-config-file","analyzedSha":"5107b0713fd78dbe8b08ee123391b1f4bcffdf12","analyzedAt":"2026-08-23T14:31:56.885Z","schemaVersion":2},"datasetVersion":"2026-08-23T16:17:53.355Z"}