浏览代码

feat: Add rewrite to webex landing page (#4102)

* feat: Add rewrite to webex landing page

* blacklist webex url

* dont cache webex

* Unregister sw for webex

* fix

* fix

* reload in callback

Co-authored-by: dwelle <luzar.david@gmail.com>
Aakansha Doshi 3 年之前
父节点
当前提交
516e7656f3
共有 2 个文件被更改,包括 18 次插入2 次删除
  1. 12 2
      src/serviceWorker.tsx
  2. 6 0
      vercel.json

+ 12 - 2
src/serviceWorker.tsx

@@ -37,6 +37,13 @@ export const register = (config?: Config) => {
     }
 
     window.addEventListener("load", () => {
+      const isWebexLP = window.location.pathname.startsWith("/webex");
+      if (isWebexLP) {
+        unregister(() => {
+          window.location.reload();
+        });
+        return false;
+      }
       const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
 
       if (isLocalhost) {
@@ -135,11 +142,14 @@ const checkValidServiceWorker = (swUrl: string, config?: Config) => {
     });
 };
 
-export const unregister = () => {
+export const unregister = (callback?: () => void) => {
   if ("serviceWorker" in navigator) {
     navigator.serviceWorker.ready
       .then((registration) => {
-        registration.unregister();
+        return registration.unregister();
+      })
+      .then(() => {
+        callback?.();
       })
       .catch((error) => {
         console.error(error.message);

+ 6 - 0
vercel.json

@@ -22,5 +22,11 @@
         }
       ]
     }
+  ],
+  "rewrites": [
+    {
+      "source": "/webex/:match*",
+      "destination": "https://excalidraw-webex-lp.vercel.app/:match*"
+    }
   ]
 }