diff options
author | Vincent Ambo <mail@tazj.in> | 2021-05-03T22·33+0200 |
---|---|---|
committer | tazjin <mail@tazj.in> | 2021-05-03T22·55+0000 |
commit | 8c0776485e81cdf1db8627c9484c8594e18678ab (patch) | |
tree | cb655870c98c8df5e2c922b258506330d5b8e2d2 /web | |
parent | 51b5475f40111d0a084b3ede6eec77d28b375536 (diff) |
feat(web/atward): Wire up query resolution to a web server r/2560
Adds a simple web server which logs all incoming requests and either sends the user to the correct destination, or gives up and displays an error (in the future there'll be fallback searches so that peopple can use this as their default search engine easily). Change-Id: I4f10472dbc74fa9cc71fad0533da38eda2b6077c Reviewed-on: https://cl.tvl.fyi/c/depot/+/3089 Tested-by: BuildkiteCI Reviewed-by: isomer <isomer@tvl.fyi>
Diffstat (limited to 'web')
-rw-r--r-- | web/atward/src/main.rs | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/web/atward/src/main.rs b/web/atward/src/main.rs index 01e0ac046482..5fe5b735ba47 100644 --- a/web/atward/src/main.rs +++ b/web/atward/src/main.rs @@ -5,6 +5,7 @@ //! browsers and attempts to send users to useful locations based on //! their search query (falling back to another search engine). use regex::Regex; +use rouille::Response; /// A query type supported by atward. It consists of a pattern on /// which to match and trigger the query, and a function to execute @@ -46,8 +47,23 @@ fn dispatch(queries: &[Query], uri: &str) -> Option<String> { None } +fn fallback() -> Response { + Response::text("no match for atward whimchst query").with_status_code(404) +} + fn main() { - println!("Hello, world!"); + let queries = queries(); + let port = std::env::var("ATWARD_PORT").unwrap_or("28973".to_string()); + let address = format!("0.0.0.0:{}", port); + + rouille::start_server(&address, move |request| { + rouille::log(&request, std::io::stderr(), || { + match dispatch(&queries, &request.url()) { + None => fallback(), + Some(destination) => Response::redirect_303(destination), + } + }) + }); } #[cfg(test)] |