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 <grfn@gws.fyi>
This commit is contained in:
Vincent Ambo 2021-06-12 16:30:24 +02:00 committed by tazjin
parent c19e3dae5f
commit 6f238c1c90

View file

@ -105,6 +105,11 @@ fn handlers() -> Vec<Handler> {
pattern: Regex::new("^cl/(?P<cl>\\d+)$").unwrap(), pattern: Regex::new("^cl/(?P<cl>\\d+)$").unwrap(),
target: |_, captures| Some(format!("https://cl.tvl.fyi/{}", &captures["cl"])), 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) // Depot paths (e.g. //web/atward or //ops/nixos/whitby/default.nix)
// TODO(tazjin): Add support for specifying lines in a query parameter // TODO(tazjin): Add support for specifying lines in a query parameter
Handler { 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] #[test]
fn request_to_query() { fn request_to_query() {
assert_eq!( assert_eq!(