Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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).
Expand Down
2 changes: 2 additions & 0 deletions lib/rack/handler/rage.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require "rage"
Rack::Handler.register("rage", "Rage::Handler") if defined?(Rack::Handler)
2 changes: 2 additions & 0 deletions lib/rackup/handler/rage.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require "rage"
Rackup::Handler.register("rage", "Rage::Handler") if defined?(Rackup::Handler)
13 changes: 12 additions & 1 deletion lib/rage-rb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down Expand Up @@ -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
6 changes: 3 additions & 3 deletions lib/rage/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
19 changes: 19 additions & 0 deletions lib/rage/handler.rb
Original file line number Diff line number Diff line change
@@ -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
Loading