about summary refs log tree commit diff
path: root/web/atward/src
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2021-06-12T14·30+0200
committertazjin <mail@tazj.in>2021-06-12T19·14+0000
commit6f238c1c9083afa303aba7a1317b8d91b1f02fd7 (patch)
tree95ba45c1f72899fae69744011295a76ab53e9703 /web/atward/src
parentc19e3dae5f6087c7e446c6be620c370d9957cf7c (diff)
feat(atward): Handle plain host queries r/2654
Redirects host queries with no parameters (e.g. `cs`, `todo`, `b`) to
the start page of the appropriate host.

Fixes: b/133

Change-Id: I9d9dee753cfb460a97b73f39bbfe3cae54aae89b
Reviewed-on: https://cl.tvl.fyi/c/depot/+/3184
Tested-by: BuildkiteCI
Reviewed-by: grfn <grfn@gws.fyi>
Diffstat (limited to 'web/atward/src')
-rw-r--r--web/atward/src/main.rs28
1 files changed, 28 insertions, 0 deletions
diff --git a/web/atward/src/main.rs b/web/atward/src/main.rs
index 7d6ded16e459..38d0e6939d4e 100644
--- a/web/atward/src/main.rs
+++ b/web/atward/src/main.rs
@@ -105,6 +105,11 @@ fn handlers() -> Vec<Handler> {
             pattern: Regex::new("^cl/(?P<cl>\\d+)$").unwrap(),
             target: |_, captures| Some(format!("https://cl.tvl.fyi/{}", &captures["cl"])),
         },
+        // Non-parameterised short hostnames should redirect to $host.tvl.fyi
+        Handler {
+            pattern: Regex::new("^(?P<host>b|cl|cs|code|at|todo)$").unwrap(),
+            target: |_, captures| Some(format!("https://{}.tvl.fyi/", &captures["host"])),
+        },
         // Depot paths (e.g. //web/atward or //ops/nixos/whitby/default.nix)
         // TODO(tazjin): Add support for specifying lines in a query parameter
         Handler {
@@ -251,6 +256,29 @@ mod tests {
     }
 
     #[test]
+    fn plain_host_queries() {
+        assert_eq!(
+            dispatch(&handlers(), &"cs".into()),
+            Some("https://cs.tvl.fyi/".to_string()),
+        );
+
+        assert_eq!(
+            dispatch(&handlers(), &"cl".into()),
+            Some("https://cl.tvl.fyi/".to_string()),
+        );
+
+        assert_eq!(
+            dispatch(&handlers(), &"b".into()),
+            Some("https://b.tvl.fyi/".to_string()),
+        );
+
+        assert_eq!(
+            dispatch(&handlers(), &"todo".into()),
+            Some("https://todo.tvl.fyi/".to_string()),
+        );
+    }
+
+    #[test]
     fn request_to_query() {
         assert_eq!(
             Query::from_request(&Request::fake_http("GET", "/?q=b%2F42", vec![], vec![]))