Initial working commit
This commit is contained in:
commit
d82edb95a9
4 changed files with 1779 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
/target
|
||||
1728
Cargo.lock
generated
Normal file
1728
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
10
Cargo.toml
Normal file
10
Cargo.toml
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
[package]
|
||||
name = "servant"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
authors = ["Andrew G. <me@nuark.xyz>"]
|
||||
|
||||
[dependencies]
|
||||
actix-web = "4.7.0"
|
||||
actix-files = "0.6.6"
|
||||
clap = { version = "4.5.7", features = ["derive"] }
|
||||
40
src/main.rs
Normal file
40
src/main.rs
Normal 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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue