about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@tvl.su>2024-08-23T10·09+0300
committertazjin <tazjin@tvl.su>2024-08-23T11·07+0000
commit73896eb075430462d89d3f47c6d52aa82005fbff (patch)
tree5b677dc146c5dda50fe1e5ca0b9ebff19ec66217
parent8041ce7cbd49aeddf7583001d7fd6a498db3380f (diff)
feat(ops/www): redirect cs.tvl.fyi to livegrep & cgit r/8553
Goodbye, Sourcegraph.

Relates to b/290.

Change-Id: Ic1cf3c1cf52ae17cdcc18c675b4c01d477644a3c
Reviewed-on: https://cl.tvl.fyi/c/depot/+/12285
Tested-by: BuildkiteCI
Reviewed-by: flokli <flokli@flokli.de>
-rw-r--r--ops/modules/www/cs.tvl.fyi.nix49
1 files changed, 42 insertions, 7 deletions
diff --git a/ops/modules/www/cs.tvl.fyi.nix b/ops/modules/www/cs.tvl.fyi.nix
index fac814baf064..9555acf9ac47 100644
--- a/ops/modules/www/cs.tvl.fyi.nix
+++ b/ops/modules/www/cs.tvl.fyi.nix
@@ -1,3 +1,5 @@
+# This configuration redirects from the previous Sourcegraph instance to
+# livegrep/cgit where appropriate.
 { config, ... }:
 
 {
@@ -13,17 +15,50 @@
       forceSSL = true;
 
       extraConfig = ''
-        location = / {
-          return 301 https://cs.tvl.fyi/depot;
+        set $lineno "";
+
+        # depot root
+        location = /depot {
+            return 301 https://code.tvl.fyi/tree/;
         }
 
-        location / {
-          proxy_set_header X-Sg-Auth "Anonymous";
-          proxy_pass http://localhost:${toString config.services.depot.sourcegraph.port};
+        # folder/file on canon
+        location ~ ^/depot/-/(blob|tree)/([^\s]*)$ {
+            set $path $2;
+            if ($args ~ ^L(\d+)(-\d+)?$) {
+                set $lineno "#n$1";
+            }
+
+            return 302 https://code.tvl.fyi/tree/$path$lineno;
+        }
+
+        # folder/file on specific commit
+        location ~ ^/depot@([a-f0-9]+)/-/(blob|tree)/([^\s]*)$ {
+            set $commit $1;
+            set $path $3;
+
+            if ($args ~ ^L(\d+)(-\d+)?$) {
+                set $lineno "#n$1";
+            }
+
+            return 302 https://code.tvl.fyi/tree/$path?id=$commit$lineno;
+        }
+
+        # commit info
+        location ~ ^/depot/-/commit/([a-f0-9]+)$ {
+            set $commit $1;
+            return 302 https://code.tvl.fyi/commit/?id=$commit;
         }
 
-        location /users/Anonymous/settings {
-          return 301 https://cs.tvl.fyi;
+        # search handler
+        # This only redirects to the new search, it doesn't try to parse and
+        # rewrite the query.
+        location /search {
+            return 302 https://grep.tvl.fyi/search;
+        }
+
+        location / {
+            return 404 "TVL code search has moved to grep.tvl.fyi and we could not figure out how to rewrite your query. Sorry!";
         }
       '';
     };