From 3f19c83a7824c0f4fa9313e71c5e4b4288b102f4 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 27 Mar 2022 23:41:12 +0100 Subject: [PATCH] actix cleanup: Remove actix test programs Signed-off-by: Ian Jackson --- TODO | 1 - daemon/Cargo.toml | 8 ---- daemon/actix-files-example.rs | 33 ------------- daemon/actix-test.rs | 90 ----------------------------------- 4 files changed, 132 deletions(-) delete mode 100644 daemon/actix-files-example.rs delete mode 100644 daemon/actix-test.rs diff --git a/TODO b/TODO index f28dc623..9fd8a5da 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,3 @@ -remove test programs template render failure logging template don't do */* thing, and strip .tera TODOs in diff diff --git a/daemon/Cargo.toml b/daemon/Cargo.toml index bdbe4a4c..88d49c2d 100644 --- a/daemon/Cargo.toml +++ b/daemon/Cargo.toml @@ -19,14 +19,6 @@ authors=["Ian Jackson ", name="daemon-otter" path="main.rs" -[[bin]] -name="actix-test" -path="actix-test.rs" - -[[bin]] -name="actix-files-example" -path="actix-files-example.rs" - [dependencies] diff --git a/daemon/actix-files-example.rs b/daemon/actix-files-example.rs deleted file mode 100644 index d4daa1ed..00000000 --- a/daemon/actix-files-example.rs +++ /dev/null @@ -1,33 +0,0 @@ -use actix_files::Files; -use actix_web::{middleware::Logger, App, HttpServer}; -use actix_web::{get, Responder, HttpResponse}; -use otter::imports::*; - -#[get("/wombat")] -async fn wombat() -> impl Responder { - HttpResponse::Ok().body("WOMBAT\n") -} - -#[actix_web::main] -async fn main() -> std::io::Result<()> { - env_logger::init_from_env(env_logger::Env::new().default_filter_or("info")); - - log::info!("starting HTTP server at http://localhost:8080"); - - HttpServer::new(|| { - App::new() - // We allow the visitor to see an index of the images at `/images`. - .service(wombat) - .service(Files::new("/images", "static/images/").show_files_listing()) - // Serve a tree of static files at the web root and specify the index file. - // Note that the root path should always be defined as the last item. The paths are - // resolved in the order they are defined. If this would be placed before the `/images` - // path then the service for the static images would never be reached. - .service(Files::new("/", "./static/root/").index_file("index.html")) - // Enable the logger. - .wrap(Logger::default()) - }) - .bind(("127.0.0.1", 8080))? - .run() - .await -} diff --git a/daemon/actix-test.rs b/daemon/actix-test.rs deleted file mode 100644 index 27c71b66..00000000 --- a/daemon/actix-test.rs +++ /dev/null @@ -1,90 +0,0 @@ - -#![allow(unused_imports)] - -use actix_web::{get, head, web, route, App, HttpServer, Responder}; -use actix_web::FromRequest; -use actix_web::HttpRequest; -use actix_web::http::Method; -use actix_web::HttpResponse; -use actix_web::dev::Payload; -use actix_web::middleware; -use actix_cors::Cors; - -use std::convert::Infallible; - -//use otter::imports::*; - -//use futures::Future; - -#[get("/{id}/{name}/index.html")] -async fn index(params: web::Path<(u32, String)>) -> impl Responder { - let (id, name) = params.into_inner(); - format!("Hello {}! id:{}", name, id) -} - -#[derive(Debug, Default)] -struct Remain { - #[allow(dead_code)] - q: Option, -} - -impl FromRequest for Remain { - type Future = futures::future::Ready>; - type Error = Infallible; - fn from_request(req: &HttpRequest, _: &mut Payload) - -> Self::Future { - let q = req.uri().query().map(ToOwned::to_owned); - let r = Remain { q }; - futures::future::ready(Ok(r)) - } -} - -//#[route("/wombat", method="GET", method="HEAD")] -#[get("/wombat")] -async fn wombat(remain: Remain) -> impl Responder { - format!("Hello {:?}", remain) -} - -fn update_cors() -> Cors { - Cors::default() - .allowed_methods([Method::GET]) - -} - -//#[route("/wombat", method="GET", method="HEAD")] -#[route("/foo", method="GET", method="HEAD", - wrap = "update_cors()")] -//#[get("/foo")] -async fn foo() -> impl Responder { - "foo\r\n" -} - -use fehler::throws; -async fn not_found_handler(method: Method) -> impl Responder { - match method { - Method::GET | Method::HEAD => HttpResponse::NotFound() - .content_type("text/plain; charset=utf-8") - .body("Not found.") - , - _ => HttpResponse::MethodNotAllowed().finish(), - } -} - -#[actix_web::main] // or #[tokio::main] -async fn main() -> std::io::Result<()> { - HttpServer::new(|| App::new() - .service(wombat) - .service(index) - .service(foo) - .default_service(web::to(not_found_handler)) - .wrap( -middleware::DefaultHeaders::new().add(( - actix_web::http::header::X_CONTENT_TYPE_OPTIONS, - "nosniff" -)) - ) - ) - .bind(("127.0.0.1", 8080))? - .run() - .await -} -- 2.30.2