]> git.ardis.lu - alu.bz/commitdiff
Use client-side redirect
authorArdis Lu <ardisglu@gmail.com>
Sun, 30 Oct 2022 07:35:13 +0000 (00:35 -0700)
committerArdis Lu <ardisglu@gmail.com>
Sun, 30 Oct 2022 07:35:13 +0000 (00:35 -0700)
functions/api.js
index.html

index ea6e05e6e1d3e28dfe3b29d0b2be5542c35cd0b2..8ef4a2db3a419ad2f66596c294a10ada9eb4306c 100644 (file)
@@ -84,7 +84,7 @@ export async function onRequestGet({ request, env }) {
   const shortUrl = url.search.substring(1);
   const fullUrl = await env.links.get(shortUrl);
   if (fullUrl === null) {
-    return Response.redirect('https://alu.bz');
+    return new Response('https://alu.bz');
   }
-  return Response.redirect(fullUrl);
+  return new Response(fullUrl);
 }
index 6f8750c5bd5ca7889cf52a2609e7cc47627011de..3910c32429e5483e2114eb4c69e5b1ad6dfad14f 100644 (file)
   </main>
 
   <script>
-    if (location.pathname !== '' && location.pathname !== '/') {
-      fetch(`/api?${location.pathname.substring(1)}`);
-    }
+    (async () => {
+      if (location.pathname !== '' && location.pathname !== '/') {
+        location = await fetch(`/api?${location.pathname.substring(1)}`).then(r => r.text());
+      }
+    })();
   </script>
   <script src="script.js" type="module"></script>
 </body>
This page took 0.037246 seconds and 4 git commands to generate.