diff options
Diffstat (limited to 'web/atward/src/main.rs')
-rw-r--r-- | web/atward/src/main.rs | 28 |
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![])) |