diff --git a/Gemfile b/Gemfile index 9c637ff..e015e4b 100644 --- a/Gemfile +++ b/Gemfile @@ -6,28 +6,37 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" } ruby '3.0.3' # Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main" -gem 'rails', '~> 7.0.0.alpha2' +gem 'rails', '~> 7.0.0.rc1' + +# The original asset pipeline for Rails [https://github.com/rails/sprockets-rails] +gem 'sprockets-rails', '>= 3.4.1' # Use postgresql as the database for Active Record gem 'pg', '~> 1.1' # Use the Puma web server [https://github.com/puma/puma] -gem 'puma', '~> 5.5' +gem 'puma', '~> 5.0' # Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails] -gem 'importmap-rails', '>= 0.3.4' +gem 'importmap-rails', '>= 0.9.2' # Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev] -gem 'turbo-rails', '>= 0.7.11' +gem 'turbo-rails', '>= 0.9.0' # Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev] -gem 'stimulus-rails', '>= 0.4.0' +gem 'stimulus-rails', '>= 0.7.3' # Build JSON APIs with ease [https://github.com/rails/jbuilder] gem 'jbuilder', '~> 2.11' # Use Redis adapter to run Action Cable in production -gem 'redis', '~> 4.5' +gem 'redis', '~> 4.0' + +# Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis] +# gem "kredis" + +# Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword] +# gem "bcrypt", "~> 3.1.7" # Windows does not include zoneinfo files, so bundle the tzinfo-data gem gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby] @@ -35,9 +44,6 @@ gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby] # Reduces boot times through caching; required in config/boot.rb gem 'bootsnap', '>= 1.4.4', require: false -# Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword] -# gem "bcrypt", "~> 3.1.7" - # Use Sass to process CSS # gem "sassc-rails", "~> 2.1" @@ -49,7 +55,7 @@ gem 'bundler-audit' gem 'rubocop-rails' group :development, :test do - # Start debugger with binding.b [https://github.com/ruby/debug] + # See https://edgeguides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem gem 'debug', '>= 1.0.0', platforms: %i[mri mingw x64_mingw] gem 'rspec-rails' gem 'rubocop-rspec' @@ -60,8 +66,8 @@ group :development do gem 'web-console', '>= 4.1.0' # Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler] - # gem "rack-mini-profiler", ">= 2.3.3" + gem 'rack-mini-profiler', '>= 2.3.3' # Speed up commands on slow machines / big apps [https://github.com/rails/spring] - # gem "spring" + # gem 'spring' end diff --git a/Gemfile.lock b/Gemfile.lock index 612425c..3b28d77 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,60 +1,61 @@ GEM remote: https://rubygems.org/ specs: - actioncable (7.0.0.alpha2) - actionpack (= 7.0.0.alpha2) - activesupport (= 7.0.0.alpha2) + actioncable (7.0.0.rc1) + actionpack (= 7.0.0.rc1) + activesupport (= 7.0.0.rc1) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailbox (7.0.0.alpha2) - actionpack (= 7.0.0.alpha2) - activejob (= 7.0.0.alpha2) - activerecord (= 7.0.0.alpha2) - activestorage (= 7.0.0.alpha2) - activesupport (= 7.0.0.alpha2) + actionmailbox (7.0.0.rc1) + actionpack (= 7.0.0.rc1) + activejob (= 7.0.0.rc1) + activerecord (= 7.0.0.rc1) + activestorage (= 7.0.0.rc1) + activesupport (= 7.0.0.rc1) mail (>= 2.7.1) - actionmailer (7.0.0.alpha2) - actionpack (= 7.0.0.alpha2) - actionview (= 7.0.0.alpha2) - activejob (= 7.0.0.alpha2) - activesupport (= 7.0.0.alpha2) + actionmailer (7.0.0.rc1) + actionpack (= 7.0.0.rc1) + actionview (= 7.0.0.rc1) + activejob (= 7.0.0.rc1) + activesupport (= 7.0.0.rc1) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (7.0.0.alpha2) - actionview (= 7.0.0.alpha2) - activesupport (= 7.0.0.alpha2) + actionpack (7.0.0.rc1) + actionview (= 7.0.0.rc1) + activesupport (= 7.0.0.rc1) rack (~> 2.0, >= 2.2.0) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.2.0) - actiontext (7.0.0.alpha2) - actionpack (= 7.0.0.alpha2) - activerecord (= 7.0.0.alpha2) - activestorage (= 7.0.0.alpha2) - activesupport (= 7.0.0.alpha2) + actiontext (7.0.0.rc1) + actionpack (= 7.0.0.rc1) + activerecord (= 7.0.0.rc1) + activestorage (= 7.0.0.rc1) + activesupport (= 7.0.0.rc1) + globalid (>= 0.6.0) nokogiri (>= 1.8.5) - actionview (7.0.0.alpha2) - activesupport (= 7.0.0.alpha2) + actionview (7.0.0.rc1) + activesupport (= 7.0.0.rc1) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.1, >= 1.2.0) - activejob (7.0.0.alpha2) - activesupport (= 7.0.0.alpha2) + activejob (7.0.0.rc1) + activesupport (= 7.0.0.rc1) globalid (>= 0.3.6) - activemodel (7.0.0.alpha2) - activesupport (= 7.0.0.alpha2) - activerecord (7.0.0.alpha2) - activemodel (= 7.0.0.alpha2) - activesupport (= 7.0.0.alpha2) - activestorage (7.0.0.alpha2) - actionpack (= 7.0.0.alpha2) - activejob (= 7.0.0.alpha2) - activerecord (= 7.0.0.alpha2) - activesupport (= 7.0.0.alpha2) - marcel (~> 1.0.0) + activemodel (7.0.0.rc1) + activesupport (= 7.0.0.rc1) + activerecord (7.0.0.rc1) + activemodel (= 7.0.0.rc1) + activesupport (= 7.0.0.rc1) + activestorage (7.0.0.rc1) + actionpack (= 7.0.0.rc1) + activejob (= 7.0.0.rc1) + activerecord (= 7.0.0.rc1) + activesupport (= 7.0.0.rc1) + marcel (~> 1.0) mini_mime (>= 1.1.0) - activesupport (7.0.0.alpha2) + activesupport (7.0.0.rc1) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 1.6, < 2) minitest (>= 5.1) @@ -113,39 +114,40 @@ GEM nio4r (~> 2.0) racc (1.6.0) rack (2.2.3) + rack-mini-profiler (2.3.3) + rack (>= 1.2.0) rack-test (1.1.0) rack (>= 1.0, < 3) - rails (7.0.0.alpha2) - actioncable (= 7.0.0.alpha2) - actionmailbox (= 7.0.0.alpha2) - actionmailer (= 7.0.0.alpha2) - actionpack (= 7.0.0.alpha2) - actiontext (= 7.0.0.alpha2) - actionview (= 7.0.0.alpha2) - activejob (= 7.0.0.alpha2) - activemodel (= 7.0.0.alpha2) - activerecord (= 7.0.0.alpha2) - activestorage (= 7.0.0.alpha2) - activesupport (= 7.0.0.alpha2) + rails (7.0.0.rc1) + actioncable (= 7.0.0.rc1) + actionmailbox (= 7.0.0.rc1) + actionmailer (= 7.0.0.rc1) + actionpack (= 7.0.0.rc1) + actiontext (= 7.0.0.rc1) + actionview (= 7.0.0.rc1) + activejob (= 7.0.0.rc1) + activemodel (= 7.0.0.rc1) + activerecord (= 7.0.0.rc1) + activestorage (= 7.0.0.rc1) + activesupport (= 7.0.0.rc1) bundler (>= 1.15.0) - railties (= 7.0.0.alpha2) - sprockets-rails (>= 2.0.0) + railties (= 7.0.0.rc1) rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) rails-html-sanitizer (1.4.2) loofah (~> 2.3) - railties (7.0.0.alpha2) - actionpack (= 7.0.0.alpha2) - activesupport (= 7.0.0.alpha2) + railties (7.0.0.rc1) + actionpack (= 7.0.0.rc1) + activesupport (= 7.0.0.rc1) method_source - rake (>= 0.13) + rake (>= 12.2) thor (~> 1.0) - zeitwerk (~> 2.5.0.beta3) + zeitwerk (~> 2.5) rainbow (3.0.0) rake (13.0.6) redis (4.5.1) - regexp_parser (2.1.1) + regexp_parser (2.2.0) reline (0.2.7) io-console (~> 0.5) rexml (3.2.5) @@ -220,17 +222,19 @@ DEPENDENCIES brakeman bundler-audit debug (>= 1.0.0) - importmap-rails (>= 0.3.4) + importmap-rails (>= 0.9.2) jbuilder (~> 2.11) pg (~> 1.1) - puma (~> 5.5) - rails (~> 7.0.0.alpha2) - redis (~> 4.5) + puma (~> 5.0) + rack-mini-profiler (>= 2.3.3) + rails (~> 7.0.0.rc1) + redis (~> 4.0) rspec-rails rubocop-rails rubocop-rspec - stimulus-rails (>= 0.4.0) - turbo-rails (>= 0.7.11) + sprockets-rails (>= 3.4.1) + stimulus-rails (>= 0.7.3) + turbo-rails (>= 0.9.0) tzinfo-data web-console (>= 4.1.0) diff --git a/app/assets/config/manifest.js b/app/assets/config/manifest.js index 4c9ab80..ddd546a 100644 --- a/app/assets/config/manifest.js +++ b/app/assets/config/manifest.js @@ -1,3 +1,4 @@ //= link_tree ../images //= link_directory ../stylesheets .css //= link_tree ../../javascript .js +//= link_tree ../../../vendor/javascript .js diff --git a/app/javascript/application.js b/app/javascript/application.js index 2706658..1c06223 100644 --- a/app/javascript/application.js +++ b/app/javascript/application.js @@ -1,5 +1,5 @@ // Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails -import "controllers" import "@hotwired/turbo-rails" +import "controllers" console.log('Hello World from application.js'); diff --git a/app/javascript/controllers/application.js b/app/javascript/controllers/application.js index 09bc93e..d865bdd 100644 --- a/app/javascript/controllers/application.js +++ b/app/javascript/controllers/application.js @@ -3,9 +3,8 @@ import { Application } from "@hotwired/stimulus" const application = Application.start() // Configure Stimulus development experience -application.warnings = true -application.debug = false -window.Stimulus = application +application.debug = false +window.Stimulus = application export { application } diff --git a/app/javascript/controllers/index.js b/app/javascript/controllers/index.js index 1d80a12..54ad4ca 100644 --- a/app/javascript/controllers/index.js +++ b/app/javascript/controllers/index.js @@ -1,5 +1,11 @@ // Import and register all your controllers from the importmap under controllers/* import { application } from "controllers/application" -import { registerControllersFrom } from "@hotwired/stimulus-importmap-autoloader" -registerControllersFrom("controllers", application) + +// Eager load all controllers defined in the import map under controllers/**/*_controller +import { eagerLoadControllersFrom } from "@hotwired/stimulus-loading" +eagerLoadControllersFrom("controllers", application) + +// Lazy load controllers as they appear in the DOM (remember not to preload controllers in import map!) +// import { lazyLoadControllersFrom } from "@hotwired/stimulus-loading" +// lazyLoadControllersFrom("controllers", application) diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index c09f91f..1d2c1c7 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -2,6 +2,7 @@ Railsondocker + <%= csrf_meta_tags %> <%= csp_meta_tag %> diff --git a/config/application.rb b/config/application.rb index b8dd670..3f90240 100644 --- a/config/application.rb +++ b/config/application.rb @@ -33,8 +33,5 @@ module Railsondocker # # config.time_zone = "Central Time (US & Canada)" # config.eager_load_paths << Rails.root.join("extras") - - # Don't generate system test files. - config.generators.system_tests = nil end end diff --git a/config/environments/development.rb b/config/environments/development.rb index ff5586d..84a57f4 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -16,6 +16,9 @@ Rails.application.configure do # Show full error reports. config.consider_all_requests_local = true + # Enable server timing + config.server_timing = true + # Enable/disable caching. By default caching is disabled. # Run rails dev:cache to toggle caching. if Rails.root.join('tmp/caching-dev.txt').exist? diff --git a/config/environments/production.rb b/config/environments/production.rb index eb9ecbf..2149251 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -55,7 +55,7 @@ Rails.application.configure do config.log_level = :info # Prepend all log lines with the following tags. - config.log_tags = [:request_id] + config.log_tags = [ :request_id ] # Use a different cache store in production. # config.cache_store = :mem_cache_store @@ -85,7 +85,7 @@ Rails.application.configure do # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new "app-name") if ENV['RAILS_LOG_TO_STDOUT'].present? - logger = ActiveSupport::Logger.new($stdout) + logger = ActiveSupport::Logger.new(STDOUT) logger.formatter = config.log_formatter config.logger = ActiveSupport::TaggedLogging.new(logger) end @@ -113,4 +113,14 @@ Rails.application.configure do # config.active_record.database_selector = { delay: 2.seconds } # config.active_record.database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver # config.active_record.database_resolver_context = ActiveRecord::Middleware::DatabaseSelector::Resolver::Session + + # Inserts middleware to perform automatic shard swapping. The `shard_selector` hash + # can be used to pass options to the `ShardSelector` middleware. The `lock` option is + # used to determine whether shard swapping should be prohibited for the request. + # + # The `shard_resolver` option is used by the middleware to determine which shard + # to switch to. The application must provide a mechanism for finding the shard name + # in a proc. See guides for an example. + # config.active_record.shard_selector = { lock: true } + # config.active_record.shard_resolver = ->(request) { Tenant.find_by!(host: request.host).shard } end diff --git a/config/environments/test.rb b/config/environments/test.rb index 3f5b681..94abc5f 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -13,10 +13,10 @@ Rails.application.configure do # Turn false under Spring and add config.action_view.cache_template_loading = true config.cache_classes = true - # Do not eager load code on boot. This avoids loading your whole application - # just for the purpose of running a single test. If you are using a tool that - # preloads Rails for running tests, you may have to set it to true. - config.eager_load = false + # Eager loading loads your whole application. When running a single test locally, + # this probably isn't necessary. It's a good idea to do in a continuous integration + # system, or in some way before deploying your code. + config.eager_load = ENV["CI"].present? # Configure public file server for tests with Cache-Control for performance. config.public_file_server.enabled = true diff --git a/config/importmap.rb b/config/importmap.rb index b559052..8dce42d 100644 --- a/config/importmap.rb +++ b/config/importmap.rb @@ -1,10 +1,7 @@ -# Use direct uploads for Active Storage (remember to import "@rails/activestorage" in your application.js) -# pin "@rails/activestorage", to: "activestorage.esm.js" +# Pin npm packages by running ./bin/importmap -# Use node modules from a JavaScript CDN by running ./bin/importmap - -pin 'application' -pin '@hotwired/turbo-rails', to: 'turbo.js' -pin '@hotwired/stimulus', to: 'stimulus.js' -pin '@hotwired/stimulus-importmap-autoloader', to: 'stimulus-importmap-autoloader.js' -pin_all_from 'app/javascript/controllers', under: 'controllers' +pin "application", preload: true +pin "@hotwired/turbo-rails", to: "turbo.min.js", preload: true +pin "@hotwired/stimulus", to: "stimulus.min.js", preload: true +pin "@hotwired/stimulus-loading", to: "stimulus-loading.js", preload: true +pin_all_from "app/javascript/controllers", under: "controllers" diff --git a/config/initializers/content_security_policy.rb b/config/initializers/content_security_policy.rb index 52f334c..f37ed8d 100644 --- a/config/initializers/content_security_policy.rb +++ b/config/initializers/content_security_policy.rb @@ -5,24 +5,23 @@ # For further information see the following documentation # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy -# Rails.application.config.content_security_policy do |policy| -# policy.default_src :self, :https -# policy.font_src :self, :https, :data -# policy.img_src :self, :https, :data -# policy.object_src :none -# policy.script_src :self, :https -# policy.style_src :self, :https -# # Specify URI for violation reports -# # policy.report_uri "/csp-violation-report-endpoint" +# Rails.application.configure do +# config.content_security_policy do |policy| +# policy.default_src :self, :https +# policy.font_src :self, :https, :data +# policy.img_src :self, :https, :data +# policy.object_src :none +# policy.script_src :self, :https +# policy.style_src :self, :https +# # Specify URI for violation reports +# # policy.report_uri "/csp-violation-report-endpoint" +# end +# +# # Generate session nonces for permitted importmap and inline scripts +# config.content_security_policy_nonce_generator = ->(request) { request.session.id.to_s } +# config.content_security_policy_nonce_directives = %w(script-src) +# +# # Report CSP violations to a specified URI. See: +# # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only +# # config.content_security_policy_report_only = true # end - -# If you are using UJS then enable automatic nonce generation -# Rails.application.config.content_security_policy_nonce_generator = -> request { SecureRandom.base64(16) } - -# Set the nonce only to specific directives -# Rails.application.config.content_security_policy_nonce_directives = %w(script-src) - -# Report CSP violations to a specified URI -# For further information see the following documentation: -# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only -# Rails.application.config.content_security_policy_report_only = true diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb index 3babc73..5118eb6 100644 --- a/config/initializers/filter_parameter_logging.rb +++ b/config/initializers/filter_parameter_logging.rb @@ -3,6 +3,6 @@ # Be sure to restart your server when you modify this file. # Configure sensitive parameters which will be filtered from the log file. -Rails.application.config.filter_parameters += %i[ - passw secret token _key crypt salt certificate otp ssn +Rails.application.config.filter_parameters += [ + :passw, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn ] diff --git a/vendor/javascript/.keep b/vendor/javascript/.keep new file mode 100644 index 0000000..e69de29