diff --git a/Gemfile b/Gemfile index d9bd57d7..172180fc 100644 --- a/Gemfile +++ b/Gemfile @@ -53,7 +53,7 @@ gem 'tailwindcss-rails' gem 'turbo-rails' gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby] -group :development, :test do +group :development, :test, :staging do gem 'brakeman', require: false gem 'bundler-audit', require: false gem 'debug', platforms: %i[mri mingw x64_mingw] diff --git a/app/assets/images/favicon/site.webmanifest.erb b/app/assets/images/favicon/site.webmanifest.erb deleted file mode 100644 index 9cff8bac..00000000 --- a/app/assets/images/favicon/site.webmanifest.erb +++ /dev/null @@ -1,19 +0,0 @@ -{ - "name": "Dawarich", - "short_name": "Dawarich", - "icons": [ - { - "src": "<%= asset_path 'favicon/android-chrome-192x192.png' %>", - "sizes": "192x192", - "type": "image/png" - }, - { - "src": "<%= asset_path 'favicon/android-chrome-512x512.png' %>", - "sizes": "512x512", - "type": "image/png" - } - ], - "theme_color": "#ffffff", - "background_color": "#ffffff", - "display": "standalone" -} diff --git a/app/views/application/_favicon.html.erb b/app/views/application/_favicon.html.erb index 5eba3e9c..cdfe669c 100644 --- a/app/views/application/_favicon.html.erb +++ b/app/views/application/_favicon.html.erb @@ -1,7 +1,7 @@ - + diff --git a/config/cable.yml b/config/cable.yml index ae88845e..e5713aea 100644 --- a/config/cable.yml +++ b/config/cable.yml @@ -1,11 +1,18 @@ -development: +default: &default adapter: redis url: <%= "#{ENV.fetch("REDIS_URL")}/#{ENV.fetch('RAILS_WS_DB', 2)}" %> +development: + <<: *default + channel_prefix: dawarich_development + +production: + <<: *default + channel_prefix: dawarich_production + +staging: + <<: *default + channel_prefix: dawarich_staging + test: adapter: test - -production: - adapter: redis - url: <%= "#{ENV.fetch("REDIS_URL")}/#{ENV.fetch('RAILS_WS_DB', 2)}" %> - channel_prefix: dawarich_production diff --git a/config/database.yml b/config/database.yml index 374dfa53..83027772 100644 --- a/config/database.yml +++ b/config/database.yml @@ -23,4 +23,4 @@ production: staging: <<: *default - database: <%= ENV['DATABASE_NAME'] || 'dawarich_staging' %> + database: <%= ENV['DATABASE_NAME'] || 'dawarich_production' %> diff --git a/config/environments/production.rb b/config/environments/production.rb index 1e4b392a..53eedb18 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -29,7 +29,7 @@ Rails.application.configure do # config.assets.css_compressor = :sass # Do not fallback to assets pipeline if a precompiled asset is missed. - config.assets.compile = true + config.assets.compile = false config.assets.content_type = { geojson: 'application/geo+json' diff --git a/config/environments/staging.rb b/config/environments/staging.rb new file mode 100644 index 00000000..0e282c59 --- /dev/null +++ b/config/environments/staging.rb @@ -0,0 +1,121 @@ +# frozen_string_literal: true + +require 'active_support/core_ext/integer/time' + +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # Code is not reloaded between requests. + config.enable_reloading = false + + # Eager load code on boot. This eager loads most of Rails and + # your application in memory, allowing both threaded web servers + # and those relying on copy on write to perform better. + # Rake tasks automatically ignore this option for performance. + config.eager_load = true + + # Full error reports are disabled and caching is turned on. + config.consider_all_requests_local = false + config.action_controller.perform_caching = true + + # Ensures that a master key has been made available in ENV["RAILS_MASTER_KEY"], config/master.key, or an environment + # key such as config/credentials/production.key. This key is used to decrypt credentials (and other encrypted files). + # config.require_master_key = true + + # Enable static file serving from the `/public` folder (turn off if using NGINX/Apache for it). + config.public_file_server.enabled = true + + # Compress CSS using a preprocessor. + # config.assets.css_compressor = :sass + + # Do not fallback to assets pipeline if a precompiled asset is missed. + config.assets.compile = false + + config.assets.content_type = { + geojson: 'application/geo+json' + } + + # Enable serving of images, stylesheets, and JavaScripts from an asset server. + # config.asset_host = "http://assets.example.com" + + # Specifies the header that your server uses for sending files. + # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for Apache + # config.action_dispatch.x_sendfile_header = "X-Accel-Redirect" # for NGINX + + # Store uploaded files on the local file system (see config/storage.yml for options). + config.active_storage.service = ENV['SELF_HOSTED'] == 'true' ? :local : :s3 + + config.silence_healthcheck_path = '/api/v1/health' + + # Mount Action Cable outside main process or domain. + # config.action_cable.mount_path = nil + # config.action_cable.url = "wss://example.com/cable" + # config.action_cable.allowed_request_origins = [ "http://example.com", /http:\/\/example.*/ ] + + # Assume all access to the app is happening through a SSL-terminating reverse proxy. + # Can be used together with config.force_ssl for Strict-Transport-Security and secure cookies. + # config.assume_ssl = true + + # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. + config.force_ssl = ENV.fetch('APPLICATION_PROTOCOL', 'http').downcase == 'https' + + # Direct logs to STDOUT + config.logger = ActiveSupport::Logger.new($stdout) + config.lograge.enabled = true + config.lograge.formatter = Lograge::Formatters::Json.new + + # Prepend all log lines with the following tags. + config.log_tags = [:request_id] + + # Info include generic and useful information about system operation, but avoids logging too much + # information to avoid inadvertent exposure of personally identifiable information (PII). If you + # want to log everything, set the level to "debug". + config.log_level = ENV.fetch('RAILS_LOG_LEVEL', 'info') + + # Use a different cache store in production. + config.cache_store = :redis_cache_store, { url: "#{ENV['REDIS_URL']}/#{ENV.fetch('RAILS_CACHE_DB', 0)}" } + + # Use a real queuing backend for Active Job (and separate queues per environment). + config.active_job.queue_adapter = :sidekiq + + config.action_mailer.perform_caching = false + + # Ignore bad email addresses and do not raise email delivery errors. + # Set this to true and configure the email server for immediate delivery to raise delivery errors. + # config.action_mailer.raise_delivery_errors = false + + # Enable locale fallbacks for I18n (makes lookups for any locale fall back to + # the I18n.default_locale when a translation cannot be found). + config.i18n.fallbacks = true + + # Don't log any deprecations. + config.active_support.report_deprecations = false + + # Do not dump schema after migrations. + config.active_record.dump_schema_after_migration = false + + # Enable DNS rebinding protection and other `Host` header attacks. + # config.hosts = [ + # "example.com", # Allow requests from example.com + # /.*\.example\.com/ # Allow requests from subdomains like `www.example.com` + # ] + # Skip DNS rebinding protection for the health check endpoint. + config.host_authorization = { exclude: ->(request) { request.path == '/api/v1/health' } } + hosts = ENV.fetch('APPLICATION_HOSTS', 'localhost').split(',') + + config.action_mailer.default_url_options = { host: ENV['DOMAIN'] } + config.hosts.concat(hosts) if hosts.present? + + config.action_mailer.delivery_method = :smtp + config.action_mailer.smtp_settings = { + address: ENV['SMTP_SERVER'], + port: ENV['SMTP_PORT'], + domain: ENV['SMTP_DOMAIN'], + user_name: ENV['SMTP_USERNAME'], + password: ENV['SMTP_PASSWORD'], + authentication: 'plain', + enable_starttls: true, + open_timeout: 5, + read_timeout: 5 + } +end diff --git a/config/initializers/mime_types.rb b/config/initializers/mime_types.rb index f874a96b..08b69174 100644 --- a/config/initializers/mime_types.rb +++ b/config/initializers/mime_types.rb @@ -1,3 +1,4 @@ # frozen_string_literal: true Mime::Type.register 'application/geo+json', :geojson +Mime::Type.register 'application/manifest+json', :webmanifest diff --git a/config/initializers/web_app_manifest.rb b/config/initializers/web_app_manifest.rb index 524a9832..bfae462d 100644 --- a/config/initializers/web_app_manifest.rb +++ b/config/initializers/web_app_manifest.rb @@ -6,13 +6,6 @@ # to asset_path in the _favicon.html.erb partial. Rails.application.config.assets.configure do |env| - mime_type = 'application/manifest+json' - extensions = ['.webmanifest'] - - if Sprockets::VERSION.to_i >= 4 - extensions << '.webmanifest.erb' - env.register_preprocessor(mime_type, Sprockets::ERBProcessor) - end - - env.register_mime_type(mime_type, extensions: extensions) + # Register .webmanifest files with the correct MIME type + env.register_mime_type 'application/manifest+json', extensions: ['.webmanifest'] end diff --git a/lib/tasks/webmanifest.rake b/lib/tasks/webmanifest.rake new file mode 100644 index 00000000..d2579e30 --- /dev/null +++ b/lib/tasks/webmanifest.rake @@ -0,0 +1,43 @@ +namespace :webmanifest do + desc "Generate site.webmanifest in public directory with correct asset paths" + task :generate => :environment do + require 'erb' + + # Make sure assets are compiled first by loading the manifest + Rails.application.assets_manifest.assets + + # Get the correct asset paths + icon_192_path = ActionController::Base.helpers.asset_path('favicon/android-chrome-192x192.png') + icon_512_path = ActionController::Base.helpers.asset_path('favicon/android-chrome-512x512.png') + + # Generate the manifest content + manifest_content = { + "name": "Dawarich", + "short_name": "Dawarich", + "icons": [ + { + "src": icon_192_path, + "sizes": "192x192", + "type": "image/png" + }, + { + "src": icon_512_path, + "sizes": "512x512", + "type": "image/png" + } + ], + "theme_color": "#ffffff", + "background_color": "#ffffff", + "display": "standalone" + }.to_json + + # Write to public/site.webmanifest + File.write(Rails.root.join('public/site.webmanifest'), manifest_content) + puts "Generated public/site.webmanifest with correct asset paths" + end +end + +# Hook to automatically generate webmanifest after assets:precompile +Rake::Task['assets:precompile'].enhance do + Rake::Task['webmanifest:generate'].invoke +end \ No newline at end of file diff --git a/public/site.webmanifest b/public/site.webmanifest new file mode 100644 index 00000000..7a172c87 --- /dev/null +++ b/public/site.webmanifest @@ -0,0 +1 @@ +{"name":"Dawarich","short_name":"Dawarich","icons":[{"src":"/assets/favicon/android-chrome-192x192-f9610e2af28e4e48ff0472572c0cb9e3902d29bccc2b07f8f03aabf684822355.png","sizes":"192x192","type":"image/png"},{"src":"/assets/favicon/android-chrome-512x512-c2ec8132d773ae99f53955360cdd5691bb38e0ed141bddebd39d896b78b5afb6.png","sizes":"512x512","type":"image/png"}],"theme_color":"#ffffff","background_color":"#ffffff","display":"standalone"} \ No newline at end of file