diff --git a/app/helpers/mailer_helper.rb b/app/helpers/mailer_helper.rb index a4c155683..c26e96273 100644 --- a/app/helpers/mailer_helper.rb +++ b/app/helpers/mailer_helper.rb @@ -14,13 +14,13 @@ module MailerHelper private def prepend_server_url(href) - return href if href.start_with? ENV['MAIL_SERVER_URL'] + return href if href.start_with? Rails.application.config.action_mailer.default_url_options[:host] new_href = '' - unless ENV['MAIL_SERVER_URL'].start_with?('http://', 'https://') + unless Rails.application.config.action_mailer.default_url_options[:host].start_with?('http://', 'https://') new_href += 'http://' end - new_href += ENV['MAIL_SERVER_URL'] + new_href += Rails.application.config.action_mailer.default_url_options[:host] new_href += ((href.start_with? '/') ? '' : '/') new_href += href new_href diff --git a/app/services/projects_json_export_service.rb b/app/services/projects_json_export_service.rb index 298e1280f..b519db39c 100644 --- a/app/services/projects_json_export_service.rb +++ b/app/services/projects_json_export_service.rb @@ -182,6 +182,6 @@ class ProjectsJsonExportService end def asset_url(asset) - ENV['MAIL_SERVER_URL'] + Rails.application.routes.url_helpers.asset_file_url_path(asset) + Rails.application.routes.url_helpers.asset_file_url_url(asset) end end diff --git a/config/environments/development.rb b/config/environments/development.rb index a2b1186af..2b9c1a2be 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -42,15 +42,17 @@ Rails.application.configure do # Store uploaded files on the local file system (see config/storage.yml for options). config.active_storage.service = ENV['ACTIVESTORAGE_SERVICE'] || :local + Rails.application.routes.default_url_options = { + host: ENV['WEB_SERVER_URL'] || ENV['MAIL_SERVER_URL'] || 'localhost' + } + + config.action_mailer.default_url_options = { host: Rails.application.routes.default_url_options[:host] } + # Don't care if the mailer can't send. config.action_mailer.raise_delivery_errors = false config.action_mailer.perform_caching = false - Rails.application.routes.default_url_options = { - host: Rails.application.secrets.mail_server_url - } - # Print deprecation notices to the Rails logger. config.active_support.deprecation = :log @@ -104,7 +106,6 @@ Rails.application.configure do else config.x.new_team_on_signup = false end - config.hosts << "dev.scinote.test" # Automatically update js-routes file # when routes.rb is changed diff --git a/config/environments/production.rb b/config/environments/production.rb index bc4505cb3..1addd35bc 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -17,13 +17,10 @@ Rails.application.configure do config.action_controller.perform_caching = true Rails.application.routes.default_url_options = { - host: Rails.application.secrets.mail_server_url + host: ENV['WEB_SERVER_URL'] || ENV['MAIL_SERVER_URL'] } - # Don't care if the mailer can't send. - config.action_mailer.default_url_options = { - host: Rails.application.secrets.mail_server_url - } + config.action_mailer.default_url_options = { host: Rails.application.routes.default_url_options[:host] } config.action_mailer.default_options = { from: Rails.application.secrets.mailer_from, reply_to: Rails.application.secrets.mailer_reply_to diff --git a/config/environments/test.rb b/config/environments/test.rb index e4393c56c..56dc88516 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -36,12 +36,13 @@ Rails.application.configure do # Store uploaded files on the local file system in a temporary directory. config.active_storage.service = :test - config.action_mailer.perform_caching = false - Rails.application.routes.default_url_options = { - host: Rails.application.secrets.mail_server_url + host: ENV['WEB_SERVER_URL'] || ENV['MAIL_SERVER_URL'] || 'localhost' } + config.action_mailer.default_url_options = { host: Rails.application.routes.default_url_options[:host] } + config.action_mailer.perform_caching = false + # Tell Action Mailer not to deliver emails to the real world. # The :test delivery method accumulates sent emails in the # ActionMailer::Base.deliveries array. diff --git a/config/secrets.yml b/config/secrets.yml index a5b890c0e..8325a8759 100644 --- a/config/secrets.yml +++ b/config/secrets.yml @@ -20,14 +20,6 @@ common: &common -# ====================================================================== -# Server address is used for mailer (in "confirm new email/..." emails, -# SciNote needs to know onto which URL to redirect the user for -# confirmation page) -# ====================================================================== - - mail_server_url: <%= ENV["MAIL_SERVER_URL"] || "localhost" %> - # ====================================================================== # Mailer configuration to define from which SMTP server to send # e-mails. diff --git a/lib/active_storage/service/custom_disk_service.rb b/lib/active_storage/service/custom_disk_service.rb index 6e0a71311..2d860c9a2 100644 --- a/lib/active_storage/service/custom_disk_service.rb +++ b/lib/active_storage/service/custom_disk_service.rb @@ -5,7 +5,7 @@ require 'active_storage/service/disk_service' module ActiveStorage class Service::CustomDiskService < Service::DiskService def url_options - ActiveStorage::Current.url_options ||= { host: Rails.application.secrets.mail_server_url } + ActiveStorage::Current.url_options ||= { host: Rails.application.routes.default_url_options[:host] } ActiveStorage::Current.url_options end end