Initial working commit

This commit is contained in:
Andrew 2024-06-13 19:05:07 +07:00
commit d82edb95a9
4 changed files with 1779 additions and 0 deletions

40
src/main.rs Normal file
View file

@ -0,0 +1,40 @@
use actix_files;
use actix_web::{App, HttpServer};
use clap::{arg, command, Parser};
#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
struct ServantArgs {
#[arg(long, default_value_t = 8080)]
port: u16,
#[arg(long, default_value_t = String::from("0.0.0.0"))]
host: String,
#[arg(long, default_value_t = String::from("/"))]
mount: String,
#[arg(long)]
serve_dir: String,
#[arg(long)]
index_file: String,
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
let args = ServantArgs::parse();
let bind_addr = format!("{}:{}", args.host, args.port);
println!("Listening on http://{}", bind_addr);
HttpServer::new(move || {
App::new().default_service(
actix_files::Files::new(&args.mount, args.serve_dir.as_str())
.index_file(args.index_file.as_str()),
)
})
.bind(bind_addr)?
.run()
.await
}