diff --git a/CHANGELOG.md b/CHANGELOG.md index 419de4f4..08e0993e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## [Unreleased] ### Added +- Support launching with `rackup` on Rack 3 by [@pratyush07-hub](https://github.com/pratyush07-hub) (#259). - [Deferred] Add tests for log context capture and backward-compatible restore by [@jsxs0](https://github.com/jsxs0) (#274). - [OpenAPI] Add support for per-endpoint OAuth2/OpenID scopes via `@auth_scope` tag by [@Piyush-Goenka](https://github.com/Piyush-Goenka) (#272). - Reuse `define_dynamic_method` and `define_maybe_yield` methods in `RageController::API` from `Rage::Internal` by [@numice](https://github.com/numice) (#273). diff --git a/lib/rack/handler/rage.rb b/lib/rack/handler/rage.rb new file mode 100644 index 00000000..37c74ba7 --- /dev/null +++ b/lib/rack/handler/rage.rb @@ -0,0 +1,2 @@ +require "rage" +Rack::Handler.register("rage", "Rage::Handler") if defined?(Rack::Handler) diff --git a/lib/rackup/handler/rage.rb b/lib/rackup/handler/rage.rb new file mode 100644 index 00000000..9a73cf5d --- /dev/null +++ b/lib/rackup/handler/rage.rb @@ -0,0 +1,2 @@ +require "rage" +Rackup::Handler.register("rage", "Rage::Handler") if defined?(Rackup::Handler) diff --git a/lib/rage-rb.rb b/lib/rage-rb.rb index 17dbddf7..7c9e5e31 100644 --- a/lib/rage-rb.rb +++ b/lib/rage-rb.rb @@ -7,8 +7,12 @@ module Rage # Builds the Rage application with the configured middlewares. + def self.application=(app) + @application = app + end + def self.application - with_middlewares(Application.new(__router), config.middleware.middlewares) + @application ||= with_middlewares(Application.new(__router), config.middleware.middlewares) end # Builds the Rage application which delegates Rails requests to `Rails.application`. @@ -200,3 +204,10 @@ module RageController require_relative "rage/env" require_relative "rage/internal" +require_relative "rage/handler" + +begin + ::Rack::Handler.register("rage", "Rage::Handler") if defined?(::Rack::Handler) + ::Rackup::Handler.register("rage", "Rage::Handler") if defined?(::Rackup::Handler) +rescue +end diff --git a/lib/rage/cli.rb b/lib/rage/cli.rb index 40b73ebe..b1d3bda8 100644 --- a/lib/rage/cli.rb +++ b/lib/rage/cli.rb @@ -83,12 +83,12 @@ def new(path = nil) option :binding, aliases: "-b", desc: "Binds Rails to the specified IP - defaults to 'localhost' in development and '0.0.0.0' in other environments" option :config, aliases: "-c", desc: "Uses a custom rack configuration" option :help, aliases: "-h", desc: "Show this message" - def server + def server(app: nil) return help("server") if options.help? set_env(options) - - app = ::Rack::Builder.parse_file(options[:config] || "config.ru") + Rage.configure { config.log_level = :error } if options[:quiet] + app ||= ::Rack::Builder.parse_file(options[:config] || "config.ru") app = app[0] if app.is_a?(Array) server_options = { service: :http, handler: app } diff --git a/lib/rage/handler.rb b/lib/rage/handler.rb new file mode 100644 index 00000000..60207fe4 --- /dev/null +++ b/lib/rage/handler.rb @@ -0,0 +1,19 @@ +module Rage + module Handler + def self.name + "Rage" + end + + def self.run(app, options = {}) + Rage.application = app + + cli_options = {} + cli_options[:port] = options[:Port] if options[:Port] + cli_options[:binding] = options[:Host] if options[:Host] + cli_options[:environment] = options[:environment] if options[:environment] + cli_options[:quiet] = options[:quiet] if options[:quiet] + + Rage::CLI.new([], cli_options).server(app: app) + end + end +end