Frontend checks if localhost before req sw.js.
This commit is contained in:
11
server.js
11
server.js
@@ -75,15 +75,10 @@ app.use("/api/", apiRouter);
|
|||||||
app.get("/dagens", (req, res) => res.redirect("/#/dagens"));
|
app.get("/dagens", (req, res) => res.redirect("/#/dagens"));
|
||||||
app.get("/winner/:id", (req, res) => res.redirect("/#/winner/" + req.params.id));
|
app.get("/winner/:id", (req, res) => res.redirect("/#/winner/" + req.params.id));
|
||||||
|
|
||||||
// push-notifications & service workers
|
// push-notifications
|
||||||
app.use("/subscription", subscriptionApi);
|
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);
|
server.listen(30030);
|
||||||
|
|||||||
@@ -9,11 +9,11 @@ var serviceWorkerRegistrationMixin = {
|
|||||||
localStorage.removeItem("push");
|
localStorage.removeItem("push");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.registerPushListener();
|
if (window.location.href.includes('localhost')) {
|
||||||
this.registerServiceWorker();
|
|
||||||
if (__ENV__ == "development") {
|
|
||||||
console.info("Service worker manually disabled while on localhost.")
|
console.info("Service worker manually disabled while on localhost.")
|
||||||
} else {
|
} else {
|
||||||
|
this.registerPushListener();
|
||||||
|
this.registerServiceWorker();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
|||||||
Reference in New Issue
Block a user