From b7493881049aaa908de04837d004ec5cf2d91b90 Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Sat, 20 Oct 2018 13:34:44 -0700 Subject: [PATCH] fix service worker --- cmd/site/main.go | 5 ++++- static/js/{pwabuilder-sw.js => sw.js} | 0 templates/base.html | 4 +--- 3 files changed, 5 insertions(+), 4 deletions(-) rename static/js/{pwabuilder-sw.js => sw.js} (100%) diff --git a/cmd/site/main.go b/cmd/site/main.go index 4295e8a..e9b4d21 100644 --- a/cmd/site/main.go +++ b/cmd/site/main.go @@ -17,7 +17,7 @@ import ( "github.com/gorilla/feeds" blackfriday "github.com/russross/blackfriday" "github.com/tj/front" - "gopkg.in/segmentio/analytics-go.v3" + analytics "gopkg.in/segmentio/analytics-go.v3" ) var port = os.Getenv("PORT") @@ -191,6 +191,9 @@ func Build() (*Site, error) { s.mux.HandleFunc("/blog/", s.showPost) s.mux.Handle("/css/", http.FileServer(http.Dir("."))) s.mux.Handle("/static/", http.FileServer(http.Dir("."))) + s.mux.HandleFunc("/sw.js", func(w http.ResponseWriter, r *http.Request) { + http.ServeFile(w, r, "./static/js/sw.js") + }) return s, nil } diff --git a/static/js/pwabuilder-sw.js b/static/js/sw.js similarity index 100% rename from static/js/pwabuilder-sw.js rename to static/js/sw.js diff --git a/templates/base.html b/templates/base.html index 4bdea31..c00bc1e 100644 --- a/templates/base.html +++ b/templates/base.html @@ -66,9 +66,7 @@ if (navigator.serviceWorker.controller) { console.log("Active service worker found, no need to register"); } else { - navigator.serviceWorker.register("/static/js/pwabuilder-sw.js", { - scope: "https://christine.website/" - }).then(function(reg) { + navigator.serviceWorker.register("/sw.js").then(function(reg) { console.log("Service worker has been registered for scope:" + reg.scope); }); }