Browse Source

feature: support loading pwa-worker from subdir (#13156)

factor2
Aaron van Meerten 2 years ago
parent
commit
78bdbe2c3f
No account linked to committer's email address
2 changed files with 18 additions and 2 deletions
  1. 7
    0
      doc/debian/jitsi-meet/jitsi-meet.example
  2. 11
    2
      index.html

+ 7
- 0
doc/debian/jitsi-meet/jitsi-meet.example View File

@@ -157,6 +157,13 @@ server {
157 157
         alias /etc/jitsi/meet/jitsi-meet.example.com-config.js;
158 158
     }
159 159
 
160
+    # Matches /(TENANT)/pwa-worker.js or /(TENANT)/manifest.json to rewrite to / and look for file
161
+    location ~ ^/([^/?&:'"]+)/(pwa-worker.js|manifest.json)$ {
162
+        set $subdomain "$1.";
163
+        set $subdir "$1/";
164
+        rewrite ^/([^/?&:'"]+)/(pwa-worker.js|manifest.json)$ /$2;
165
+    }
166
+
160 167
     # BOSH for subdomains
161 168
     location ~ ^/([^/?&:'"]+)/http-bind {
162 169
         set $subdomain "$1.";

+ 11
- 2
index.html View File

@@ -13,10 +13,19 @@
13 13
     <link rel="manifest" id="manifest-placeholder">
14 14
 
15 15
     <script>
16
+        function contextRoot(pathname) {
17
+            const contextRootEndIndex = pathname.lastIndexOf('/');
18
+
19
+            return (
20
+                contextRootEndIndex === -1
21
+                ? '/'
22
+                : pathname.substring(0, contextRootEndIndex + 1)
23
+            );
24
+        }
16 25
         window.EXCALIDRAW_ASSET_PATH = 'libs/';
17 26
         // Dynamically generate the manifest location URL. It must be served from the document origin, and we may have
18 27
         // the base pointing to the CDN. This way we can generate a full URL which will bypass the base.
19
-        document.querySelector('#manifest-placeholder').setAttribute('href', window.location.origin + '/manifest.json');
28
+        document.querySelector('#manifest-placeholder').setAttribute('href', window.location.origin + contextRoot(window.location.pathname) + 'manifest.json');
20 29
 
21 30
         document.addEventListener('DOMContentLoaded', () => {
22 31
             if (!JitsiMeetJS.app) {
@@ -40,7 +49,7 @@
40 49
 
41 50
             if (shouldRegisterWorker) {
42 51
                 navigator.serviceWorker
43
-                    .register(window.location.origin + '/pwa-worker.js')
52
+                    .register(window.location.origin + contextRoot(window.location.pathname) + '/pwa-worker.js')
44 53
                     .then(reg => {
45 54
                         console.log('Service worker registered.', reg);
46 55
                     })

Loading…
Cancel
Save