FIX: Support old Service Worker source file path to avoid routing errors.

This commit is contained in:
Guo Xiang Tan 2018-02-19 08:04:15 +08:00
parent 33df2d6a02
commit d601a6b23c
2 changed files with 7 additions and 1 deletions

View File

@ -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;

View File

@ -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