From d601a6b23cf270f79d635eadd56590188fa2ea20 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Mon, 19 Feb 2018 08:04:15 +0800 Subject: [PATCH] FIX: Support old Service Worker source file path to avoid routing errors. --- config/nginx.sample.conf | 2 +- config/routes.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/config/nginx.sample.conf b/config/nginx.sample.conf index 6253e04146a..f7544fdce1a 100644 --- a/config/nginx.sample.conf +++ b/config/nginx.sample.conf @@ -188,7 +188,7 @@ server { # This big block is needed so we can selectively enable # acceleration for backups and avatars # see note about repetition above - location ~ ^/(letter_avatar/|user_avatar|highlight-js|stylesheets|favicon/proxied|service-worker-.*.js) { + location ~ ^/(letter_avatar/|user_avatar|highlight-js|stylesheets|favicon/proxied|service-worker) { proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; diff --git a/config/routes.rb b/config/routes.rb index a7409d3afd9..bb1b8c8fedb 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -697,6 +697,12 @@ Discourse::Application.routes.draw do delete "draft" => "draft#destroy" if service_worker_asset = Rails.application.assets_manifest.assets['service-worker.js'] + # https://developers.google.com/web/fundamentals/codelabs/debugging-service-workers/ + # Normally the browser will wait until a user closes all tabs that contain the + # 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" => redirect(service_worker_asset), format: :js get service_worker_asset => "static#service_worker_asset", format: :js end