From 8c0776485e81cdf1db8627c9484c8594e18678ab Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Tue, 4 May 2021 00:33:53 +0200 Subject: feat(web/atward): Wire up query resolution to a web server 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 --- web/atward/src/main.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'web/atward') 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 { 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)] -- cgit 1.4.1