Skip to content
This repository has been archived by the owner on Aug 4, 2024. It is now read-only.

Commit

Permalink
HotFix query url for Json manifest (workadventure#2761)
Browse files Browse the repository at this point in the history
  • Loading branch information
gparant authored Nov 2, 2022
1 parent e69923d commit 4e011c5
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
8 changes: 8 additions & 0 deletions play/public/service-worker-dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ let urlsToCache = [
];

self.addEventListener('install', function(event) {
// url to cache
if(event.target && event.target.serviceWorker && event.target.serviceWorker.scriptURL){
const url = new URL(event.target.serviceWorker.scriptURL);
const searchParams = new URLSearchParams(url.search);
const playUri = searchParams.get('playUri');
urlsToCache = [playUri];
}

// Perform install steps
event.waitUntil(
caches.open(CACHE_NAME)
Expand Down
8 changes: 8 additions & 0 deletions play/public/service-worker-prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ let urlsToCache = [
];

self.addEventListener('install', function(event) {
// url to cache
if(event.target && event.target.serviceWorker && event.target.serviceWorker.scriptURL){
const url = new URL(event.target.serviceWorker.scriptURL);
const searchParams = new URLSearchParams(url.search);
const playUri = searchParams.get('playUri');
urlsToCache = [playUri];
}

// Perform install steps
event.waitUntil(
caches.open(CACHE_NAME)
Expand Down
20 changes: 18 additions & 2 deletions play/src/front/Network/ServiceWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@ import { NODE_ENV } from "../Enum/EnvironmentVariable";
export class _ServiceWorker {
constructor() {
if ("serviceWorker" in navigator) {
if (navigator.storage && navigator.storage.persist) {
navigator.storage
.persist()
.then((persistent) => {
if (persistent) {
console.log("Storage will not be cleared except by explicit user action");
} else {
console.log("Storage may be cleared by the UA under storage pressure.");
}
})
.catch((err) => console.error("_ServiceWorker => err", err));
}
this.init();
}
}
Expand All @@ -11,7 +23,9 @@ export class _ServiceWorker {
//Check node env and if is development, use service worker dev file
if (NODE_ENV === "development") {
navigator.serviceWorker
.register("/service-worker-dev.js")
.register(
`/service-worker-dev.js?playUri=${window.location.protocol}//${window.location.host}${window.location.pathname}`
)
.then((serviceWorker) => {
console.info("Service Worker registered: ", serviceWorker);
})
Expand All @@ -21,7 +35,9 @@ export class _ServiceWorker {
return;
}
navigator.serviceWorker
.register("/service-worker-prod.js")
.register(
`/service-worker-prod.js?playUri=${window.location.protocol}//${window.location.host}${window.location.pathname}`
)
.then((serviceWorker) => {
console.info("Service Worker registered: ", serviceWorker);
})
Expand Down
5 changes: 4 additions & 1 deletion play/src/pusher/controllers/FrontController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ export class FrontController extends BaseHttpController {
});

this.app.get("/static/images/favicons/manifest.json", (req: Request, res: Response) => {
return this.displayManifestJson(req, res, req.get("url"));
if (req.query.url == undefined) {
return res.status(500).send("playUrl is empty in query pramater of the request");
}
return this.displayManifestJson(req, res, req.query.url.toString());
});

this.app.get("/login", (req: Request, res: Response) => {
Expand Down

0 comments on commit 4e011c5

Please sign in to comment.