diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index d8b642ad8c3..f4ef9660d67 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -456,6 +456,8 @@ module ApplicationHelper end def client_side_setup_data + service_worker_url = Rails.env.development? ? 'service-worker.js' : Rails.application.assets_manifest.assets['service-worker.js'] + setup_data = { cdn: Rails.configuration.action_controller.asset_host, base_url: Discourse.base_url, @@ -463,7 +465,7 @@ module ApplicationHelper environment: Rails.env, letter_avatar_version: LetterAvatar.version, markdown_it_url: script_asset_path('markdown-it-bundle'), - service_worker_url: 'service-worker.js', + service_worker_url: service_worker_url, default_locale: SiteSetting.default_locale, asset_version: Discourse.assets_digest, disable_custom_css: loading_admin?, diff --git a/config/nginx.sample.conf b/config/nginx.sample.conf index 3bcb9c2d70a..538e29fab4a 100644 --- a/config/nginx.sample.conf +++ b/config/nginx.sample.conf @@ -33,13 +33,6 @@ map $http_x_forwarded_proto $thescheme { log_format log_discourse '[$time_local] "$http_host" $remote_addr "$request" "$http_user_agent" "$sent_http_x_discourse_route" $status $bytes_sent "$http_referer" $upstream_response_time $request_time "$sent_http_x_discourse_username"'; -# Allow bypass cache from localhost -geo $bypass_cache { - default 0; - 127.0.0.1 1; - ::1 1; -} - server { access_log /var/log/nginx/access.log log_discourse; @@ -231,15 +224,6 @@ server { proxy_cache_valid 200 301 302 7d; proxy_cache_valid any 1m; proxy_pass http://discourse; - - # Allow service worker cache to be re-cached by localhost requests only - # Forward public cache control - location ~ ^/service-worker { - proxy_cache_bypass $bypass_cache; - proxy_hide_header "Cache-Control"; - add_header Cache-Control max-age=31556952,public; - proxy_pass http://discourse; - } break; } diff --git a/config/routes.rb b/config/routes.rb index 1f2a1015f99..eb1bab02127 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -810,7 +810,7 @@ Discourse::Application.routes.draw do # current site before updating to a new Service Worker. # Support the old Service Worker path to avoid routing error filling up the # logs. - get "/service-worker.js" => "static#service_worker_asset", format: :js + get "/service-worker.js" => redirect(relative_url_root + service_worker_asset, status: 302), format: :js get service_worker_asset => "static#service_worker_asset", format: :js elsif Rails.env.development? get "/service-worker.js" => "static#service_worker_asset", format: :js diff --git a/lib/tasks/assets.rake b/lib/tasks/assets.rake index cb2e9795f65..7625fece589 100644 --- a/lib/tasks/assets.rake +++ b/lib/tasks/assets.rake @@ -68,19 +68,6 @@ task 'assets:precompile:css' => 'environment' do end end -task 'assets:flush_sw' => 'environment' do - begin - hostname = Discourse.current_hostname - default_port = SiteSetting.force_https? ? 443 : 80 - port = SiteSetting.port.to_i > 0 ? SiteSetting.port : default_port - STDERR.puts "Flushing service worker script" - `curl -s -m 1 --resolve '#{hostname}:#{port}:127.0.0.1' #{Discourse.base_url}/service-worker.js > /dev/null` - STDERR.puts "done" - rescue - STDERR.puts "Warning: unable to flush service worker script" - end -end - def assets_path "#{Rails.root}/public/assets" end