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"));
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
-use actix_web::{get, web, App, HttpServer, Responder};
+#![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;
}
}
+//#[route("/wombat", method="GET", method="HEAD")]
#[get("/wombat")]
async fn wombat(remain: Remain) -> impl Responder {
format!("Hello {:?}", remain)
}
+//#[route("/wombat", method="GET", method="HEAD")]
+#[route("/foo", method="GET", method="HEAD")]
+//#[get("/foo")]
+async fn foo() -> impl Responder {
+ "foo\r\n"
+}
+
use fehler::throws;
-#[throws(actix_web::Error)]
async fn not_found_handler(method: Method) -> impl Responder {
match method {
- Method::GET => HttpResponse::NotFound().body("Not found.")
+ Method::GET | Method::HEAD => HttpResponse::NotFound()
+ .content_type("text/plain; charset=utf-8")
+ .body("Not found.")
,
_ => HttpResponse::MethodNotAllowed().finish(),
}
HttpServer::new(|| App::new()
.service(wombat)
.service(index)
+ .service(foo)
.default_service(web::to(not_found_handler))
)
.bind(("127.0.0.1", 8080))?