From 6f238c1c9083afa303aba7a1317b8d91b1f02fd7 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Sat, 12 Jun 2021 16:30:24 +0200 Subject: feat(atward): Handle plain host queries 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 --- web/atward/src/main.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'web/atward/src') diff --git a/web/atward/src/main.rs b/web/atward/src/main.rs index 7d6ded16e4..38d0e6939d 100644 --- a/web/atward/src/main.rs +++ b/web/atward/src/main.rs @@ -105,6 +105,11 @@ fn handlers() -> Vec { pattern: Regex::new("^cl/(?P\\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("^(?Pb|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 { @@ -250,6 +255,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!( -- cgit 1.4.1