@indextools/index-games 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,4 @@
1
1
  "use strict";
2
- const stockSW = "./sw.js";
3
2
 
4
3
  /**
5
4
  * List of hostnames that are allowed to run serviceworkers on http://
@@ -8,7 +7,7 @@ const swAllowedHostnames = ["localhost", "127.0.0.1"];
8
7
 
9
8
  /**
10
9
  * Global util
11
- * Used in 404.html and index.html
10
+ * Used in index.html, 404.html, and games
12
11
  */
13
12
  async function registerSW() {
14
13
  if (!navigator.serviceWorker) {
@@ -21,5 +20,10 @@ async function registerSW() {
21
20
  throw new Error("Your browser doesn't support service workers.");
22
21
  }
23
22
 
24
- await navigator.serviceWorker.register(stockSW);
23
+ let publicDir = new URL("./", location.href).pathname;
24
+ if (publicDir.endsWith("/games/")) {
25
+ publicDir = new URL("../", location.href).pathname;
26
+ }
27
+ const swUrl = publicDir + "sw.js";
28
+ await navigator.serviceWorker.register(swUrl, { scope: publicDir });
25
29
  }
package/public/sw.js CHANGED
@@ -1,9 +1,21 @@
1
1
  importScripts("https://unpkg.com/@mercuryworkshop/scramjet@2.0.0-alpha/dist/scramjet.all.js");
2
+ importScripts("https://unpkg.com/@titaniumnetwork-dev/ultraviolet@3.2.10/dist/uv.bundle.js");
3
+ importScripts("https://unpkg.com/@titaniumnetwork-dev/ultraviolet@3.2.10/dist/uv.config.js");
4
+ importScripts("https://unpkg.com/@titaniumnetwork-dev/ultraviolet@3.2.10/dist/uv.sw.js");
2
5
 
3
6
  const { ScramjetServiceWorker } = $scramjetLoadWorker();
4
7
  const scramjet = new ScramjetServiceWorker();
5
8
 
9
+ const baseDir = new URL("./", location.href).pathname;
10
+ if (self.__uv$config) {
11
+ self.__uv$config.prefix = baseDir + "uv/";
12
+ }
13
+ const uv = new self.UVServiceWorker(self.__uv$config);
14
+
6
15
  async function handleRequest(event) {
16
+ if (uv.route(event)) {
17
+ return uv.fetch(event);
18
+ }
7
19
  await scramjet.loadConfig();
8
20
  if (scramjet.route(event)) {
9
21
  return scramjet.fetch(event);