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

This commit is contained in:
Aaron van Meerten
2023-04-03 10:06:10 -05:00
committed by GitHub
parent e781bc9458
commit 78bdbe2c3f
2 changed files with 18 additions and 2 deletions

View File

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

View File

@@ -13,10 +13,19 @@
<link rel="manifest" id="manifest-placeholder">
<script>
function contextRoot(pathname) {
const contextRootEndIndex = pathname.lastIndexOf('/');
return (
contextRootEndIndex === -1
? '/'
: pathname.substring(0, contextRootEndIndex + 1)
);
}
window.EXCALIDRAW_ASSET_PATH = 'libs/';
// Dynamically generate the manifest location URL. It must be served from the document origin, and we may have
// the base pointing to the CDN. This way we can generate a full URL which will bypass the base.
document.querySelector('#manifest-placeholder').setAttribute('href', window.location.origin + '/manifest.json');
document.querySelector('#manifest-placeholder').setAttribute('href', window.location.origin + contextRoot(window.location.pathname) + 'manifest.json');
document.addEventListener('DOMContentLoaded', () => {
if (!JitsiMeetJS.app) {
@@ -40,7 +49,7 @@
if (shouldRegisterWorker) {
navigator.serviceWorker
.register(window.location.origin + '/pwa-worker.js')
.register(window.location.origin + contextRoot(window.location.pathname) + '/pwa-worker.js')
.then(reg => {
console.log('Service worker registered.', reg);
})