diff options
author | xengineering <mail2xengineering@protonmail.com> | 2021-03-05 18:35:48 +0100 |
---|---|---|
committer | xengineering <mail2xengineering@protonmail.com> | 2021-03-05 18:35:48 +0100 |
commit | f9714353664507845bad9e5856f5396ab3d629b2 (patch) | |
tree | feded85f317a466ed7ee68ad8dfddab7a55ec71d | |
parent | 1e59286e7d3516b27f143dd2db8760bac2af30ed (diff) | |
download | web-template-f9714353664507845bad9e5856f5396ab3d629b2.tar web-template-f9714353664507845bad9e5856f5396ab3d629b2.tar.zst web-template-f9714353664507845bad9e5856f5396ab3d629b2.zip |
Serve static Files and Index at /actix
-rw-r--r-- | actix/src/main.rs | 23 | ||||
-rw-r--r-- | lib/html/example.html | 2 | ||||
l--------- | static/css/xengineering.css | 1 |
3 files changed, 11 insertions, 15 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()) + } diff --git a/lib/html/example.html b/lib/html/example.html index a406de7..9b85d6f 100644 --- a/lib/html/example.html +++ b/lib/html/example.html @@ -8,7 +8,7 @@ <meta charset="utf-8"/> <meta name="viewport" content="width=device-width, initial-scale=1.0"> - <link rel="stylesheet" href="css/xengineering.css" type="text/css"> + <link rel="stylesheet" href="static/css/xengineering.css" type="text/css"> </head> diff --git a/static/css/xengineering.css b/static/css/xengineering.css new file mode 120000 index 0000000..73f09ef --- /dev/null +++ b/static/css/xengineering.css @@ -0,0 +1 @@ +../../lib/css/xengineering.css
\ No newline at end of file |