From cb6fc9fb2e1a8551aa7c5f002dbfa24404426cfd Mon Sep 17 00:00:00 2001 From: Sony Mathew Date: Tue, 1 Sep 2020 11:39:18 +0530 Subject: [PATCH] fix: fonts cors issue with cdn (#1182) --- config/environments/production.rb | 9 +++++++++ config/environments/staging.rb | 9 +++++++++ config/environments/test.rb | 9 +++++++++ config/initializers/assets.rb | 4 ++++ 4 files changed, 31 insertions(+) diff --git a/config/environments/production.rb b/config/environments/production.rb index b796d6acd..6f7c97eee 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -119,4 +119,13 @@ Rails.application.configure do config.action_mailbox.ingress = ENV.fetch('RAILS_INBOUND_EMAIL_SERVICE', 'relay').to_sym Rails.application.routes.default_url_options = { host: ENV['FRONTEND_URL'] } + + # font cors issue with CDN + # Ref: https://stackoverflow.com/questions/56960709/rails-font-cors-policy + config.middleware.insert_before 0, Rack::Cors do + allow do + origins '*' + resource '/packs/*', headers: :any, methods: [:get, :options] + end + end end diff --git a/config/environments/staging.rb b/config/environments/staging.rb index 585f35da4..53c0934c7 100644 --- a/config/environments/staging.rb +++ b/config/environments/staging.rb @@ -102,4 +102,13 @@ Rails.application.configure do # Do not dump schema after migrations. config.active_record.dump_schema_after_migration = false + + # font cors issue with CDN + # Ref: https://stackoverflow.com/questions/56960709/rails-font-cors-policy + config.middleware.insert_before 0, Rack::Cors do + allow do + origins '*' + resource '/packs/*', headers: :any, methods: [:get, :options] + end + end end diff --git a/config/environments/test.rb b/config/environments/test.rb index 1dbfa63ef..6a2534654 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -51,4 +51,13 @@ Rails.application.configure do # Raises error for missing translations. # config.action_view.raise_on_missing_translations = true config.log_level = ENV.fetch('LOG_LEVEL', 'debug').to_sym + + # font cors issue with CDN + # Ref: https://stackoverflow.com/questions/56960709/rails-font-cors-policy + config.middleware.insert_before 0, Rack::Cors do + allow do + origins '*' + resource '/packs/*', headers: :any, methods: [:get, :options] + end + end end diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index 351f7b42b..9ac37c731 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -13,3 +13,7 @@ Rails.application.config.assets.paths << Rails.root.join('node_modules') # folder are already added. # Rails.application.config.assets.precompile += %w( admin.js admin.css ) Rails.application.config.assets.precompile += %w[dashboardChart.js] + +# to take care of fonts in assets pre-compiling +# Ref: https://stackoverflow.com/questions/56960709/rails-font-cors-policy +Rails.application.config.assets.precompile << /\.(?:svg|eot|woff|ttf|woff2)$/