diff options
Diffstat (limited to 'actix/src/main.rs')
-rw-r--r-- | actix/src/main.rs | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/actix/src/main.rs b/actix/src/main.rs index c350cdc..90988c4 100644 --- a/actix/src/main.rs +++ b/actix/src/main.rs @@ -1,8 +1,9 @@ // vim: tabstop=4 shiftwidth=4 expandtab +use std::fs; extern crate clap; -use actix_files as fs; +use actix_files; use actix_web::{get, App, HttpResponse, HttpServer, Responder}; @@ -10,7 +11,6 @@ use actix_web::{get, App, HttpResponse, HttpServer, Responder}; struct RuntimeConfig { address: String, port: String, - webroot_path: String, } @@ -18,14 +18,13 @@ struct RuntimeConfig { async fn main() -> std::io::Result<()> { let cfg = get_runtime_config(); - println!("{:?}", cfg); println!("Binding to http://{}:{}", cfg.address, cfg.port); HttpServer::new(|| { App::new() - .service(index_handler) - .service(fs::Files::new("/static", "./static").show_files_listing()) + .service(index) + .service(actix_files::Files::new("/static", "./static")) // you may append .show_files_listing() }) .bind(format!("{}:{}", cfg.address, cfg.port))? .run() @@ -48,23 +47,19 @@ fn get_runtime_config() -> RuntimeConfig { .short("p") .takes_value(true) .default_value("8080")) - .arg(clap::Arg::with_name("webroot_path") - .help("Path to static files") - .long("webroot-path") - .short("w") - .takes_value(true) - .default_value("/srv/http")) .get_matches(); RuntimeConfig { address: cli_matches.value_of("address").unwrap().to_string(), port: cli_matches.value_of("port").unwrap().to_string(), - webroot_path: cli_matches.value_of("webroot_path").unwrap().to_string(), } } #[get("/")] -async fn index_handler() -> impl Responder { - HttpResponse::Ok().body("Hello world!") +async fn index() -> impl Responder { + HttpResponse::Ok() + .content_type("text/html") + .body(fs::read_to_string("./static/index.html").unwrap()) + } |