Skip to content

Commit

Permalink
Merge pull request #203 from rails/api-mode
Browse files Browse the repository at this point in the history
Support API-only Rails apps
  • Loading branch information
rosa authored Nov 15, 2024
2 parents 0cd4cb0 + 9d6a8b3 commit 9714469
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 13 deletions.
14 changes: 6 additions & 8 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ GEM
parser (3.3.0.5)
ast (~> 2.4.1)
racc
propshaft (1.1.0)
actionpack (>= 7.0.0)
activesupport (>= 7.0.0)
rack
railties (>= 7.0.0)
psych (5.1.2)
stringio
public_suffix (5.0.4)
Expand Down Expand Up @@ -248,13 +253,6 @@ GEM
fugit (~> 1.11.0)
railties (>= 7.1)
thor (~> 1.3.1)
sprockets (4.2.1)
concurrent-ruby (~> 1.0)
rack (>= 2.2.4, < 4)
sprockets-rails (3.4.2)
actionpack (>= 5.2)
activesupport (>= 5.2)
sprockets (>= 3.0.0)
sqlite3 (2.2.0-aarch64-linux-gnu)
sqlite3 (2.2.0-arm-linux-gnu)
sqlite3 (2.2.0-arm64-darwin)
Expand Down Expand Up @@ -297,6 +295,7 @@ DEPENDENCIES
debug
mission_control-jobs!
mocha
propshaft
puma
redis
redis-namespace
Expand All @@ -307,7 +306,6 @@ DEPENDENCIES
rubocop-rails-omakase
selenium-webdriver
solid_queue (~> 1.0.1)
sprockets-rails
sqlite3

BUNDLED WITH
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,20 @@ And that's it. With this alone, you should be able to access Mission Control Job

![Failed jobs tab in a simple app](docs/images/failed-jobs-simple.png)

### API-only apps or apps using `vite_rails` and other asset pipelines outside Rails

If you want to use this gem with an [API-only Rails app](https://guides.rubyonrails.org/api_app.html) or an app that's using `vite_ruby`/`vite_rails`, or some other custom asset pipeline different from Sprockets and Propshaft, you need just one more thing: configure an asset pipeline so you can serve the JavaScript and CSS included in this gem. We recommend to use [`Propshaft`](https://github.com/rails/propshaft). You simply need to add this line to your application's Gemfile:

```ruby
gem "propshaft"
```

Then execute
```bash
$ bundle install
```

And you should be ready to go.

### Authentication and base controller class

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
class MissionControl::Jobs::ApplicationController < MissionControl::Jobs.base_controller_class.constantize
ActionController::Base::MODULES.each do |mod|
include mod unless self < mod
end

layout "mission_control/jobs/application"

# Include helpers if not already included
helper MissionControl::Jobs::ApplicationHelper unless self < MissionControl::Jobs::ApplicationHelper
helper Importmap::ImportmapTagsHelper unless self < Importmap::ImportmapTagsHelper

include MissionControl::Jobs::ApplicationScoped, MissionControl::Jobs::NotFoundRedirections
include MissionControl::Jobs::AdapterFeatures

Expand Down
8 changes: 8 additions & 0 deletions lib/mission_control/jobs/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ module Jobs
class Engine < ::Rails::Engine
isolate_namespace MissionControl::Jobs

initializer "mission_control-jobs.middleware" do |app|
if app.config.api_only
app.middleware.use ActionDispatch::Flash
app.middleware.use ::Rack::MethodOverride
end
end

config.mission_control = ActiveSupport::OrderedOptions.new unless config.try(:mission_control)
config.mission_control.jobs = ActiveSupport::OrderedOptions.new

Expand Down Expand Up @@ -80,6 +87,7 @@ class Engine < ::Rails::Engine
end

initializer "mission_control-jobs.assets" do |app|
app.config.assets.paths << root.join("app/assets/stylesheets")
app.config.assets.paths << root.join("app/javascript")
app.config.assets.precompile += %w[ mission_control_jobs_manifest ]
end
Expand Down
2 changes: 1 addition & 1 deletion mission_control-jobs.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "rubocop-performance"
spec.add_development_dependency "rubocop-rails-omakase"
spec.add_development_dependency "better_html"
spec.add_development_dependency "sprockets-rails"
spec.add_development_dependency "propshaft"
spec.add_development_dependency "sqlite3"
spec.add_development_dependency "puma"
end
3 changes: 0 additions & 3 deletions test/dummy/app/assets/config/manifest.js

This file was deleted.

2 changes: 1 addition & 1 deletion test/dummy/config/application.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require_relative "boot"

require "rails/all"
require "sprockets/railtie"
require "propshaft"

require "resque"
require "solid_queue"
Expand Down

0 comments on commit 9714469

Please sign in to comment.