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:
		
							parent
							
								
									c19e3dae5f
								
							
						
					
					
						commit
						6f238c1c90
					
				
					 1 changed files with 28 additions and 0 deletions
				
			
		|  | @ -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 { | ||||
|  | @ -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!( | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue