diff --git a/server.js b/server.js index a10267f..6ab4922 100644 --- a/server.js +++ b/server.js @@ -75,15 +75,10 @@ app.use("/api/", apiRouter); app.get("/dagens", (req, res) => res.redirect("/#/dagens")); app.get("/winner/:id", (req, res) => res.redirect("/#/winner/" + req.params.id)); -// push-notifications & service workers +// push-notifications app.use("/subscription", subscriptionApi); -app.use("/service-worker.js", function(req, res) { - if (process.env.NODE_ENV == "development") { - return res.end(); // cancel serving service worker if localhost - } - res.sendFile(path.join(__dirname, "src/serviceWorker.js")); -}); -app.use("/", (req, res) => res.sendFile(path.join(__dirname + "/dist/index.html"))); +// No other route defined, return index file +app.use("/", (req, res) => res.sendFile(path.join(__dirname + "/public/dist/index.html"))); server.listen(30030); diff --git a/src/mixins/ServiceWorkerMixin.js b/src/mixins/ServiceWorkerMixin.js index 5442545..f0f3a31 100644 --- a/src/mixins/ServiceWorkerMixin.js +++ b/src/mixins/ServiceWorkerMixin.js @@ -9,11 +9,11 @@ var serviceWorkerRegistrationMixin = { localStorage.removeItem("push"); } } - this.registerPushListener(); - this.registerServiceWorker(); - if (__ENV__ == "development") { + if (window.location.href.includes('localhost')) { console.info("Service worker manually disabled while on localhost.") } else { + this.registerPushListener(); + this.registerServiceWorker(); } }, methods: {