Skip to content

Commit d7f9347

Browse files
authored
Merge pull request rails#52571 from chunlea/chunlea/remove-pwa-for-api-only
Remove PWA views and routes if its an API only project
2 parents b45e4a8 + 97382b4 commit d7f9347

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

railties/lib/rails/generators/rails/app/app_generator.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,7 @@ def delete_app_views_if_api_option
491491
remove_dir "app/views"
492492
else
493493
remove_file "app/views/layouts/application.html.erb"
494+
remove_dir "app/views/pwa"
494495
end
495496
end
496497
end

railties/lib/rails/generators/rails/app/templates/config/routes.rb.tt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ Rails.application.routes.draw do
55
# Can be used by load balancers and uptime monitors to verify that the app is live.
66
get "up", to: "rails/health#show", as: :rails_health_check
77

8+
<%- unless options.api? -%>
89
# Render dynamic PWA files from app/views/pwa/*
910
get "service-worker", to: "rails/pwa#service_worker", as: :pwa_service_worker
1011
get "manifest", to: "rails/pwa#manifest", as: :pwa_manifest
1112

13+
<%- end -%>
1214
# Defines the root path route ("/")
1315
# root "posts#index"
1416
end

railties/test/generators/generators_test_helper.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,12 @@ def with_database_configuration(database_name = "secondary")
6262

6363
def copy_routes
6464
routes = File.expand_path("../../lib/rails/generators/rails/app/templates/config/routes.rb.tt", __dir__)
65+
routes = evaluate_template(routes, {
66+
options: ActiveSupport::OrderedOptions.new
67+
})
6568
destination = File.join(destination_root, "config")
6669
FileUtils.mkdir_p(destination)
67-
FileUtils.cp routes, File.join(destination, "routes.rb")
70+
File.write File.join(destination, "routes.rb"), routes
6871
end
6972

7073
def copy_gemfile(*gemfile_entries)

0 commit comments

Comments
 (0)