51 lines
1.2 KiB
Rust
51 lines
1.2 KiB
Rust
mod server;
|
|
mod router;
|
|
mod response;
|
|
|
|
use std::path::PathBuf;
|
|
use std::sync::Arc;
|
|
use logger_rust::*;
|
|
|
|
use clap::Parser;
|
|
|
|
// 1CA:b6e8ae4ca8acae66aa3dfd3f0a377e91d041e4d7 ; added clap as a parser, its way cleaner
|
|
#[derive(Parser, Debug)]
|
|
#[command(name = "http-rs")]
|
|
#[command(about = "http-rs webserver")]
|
|
struct Arguments {
|
|
/// port where we should serve on
|
|
#[arg(short, long, default_value_t = 8080)]
|
|
port : u16,
|
|
|
|
/// where we should serve from
|
|
#[arg(short, long, default_value = ".")]
|
|
root: PathBuf,
|
|
|
|
/// number of threads to run on
|
|
#[arg(short, long)]
|
|
threads: Option<usize>,
|
|
}
|
|
|
|
|
|
fn main() {
|
|
let args = Arguments::parse();
|
|
let root = Arc::new(args.root);
|
|
|
|
if !root.exists() || !root.is_dir() {
|
|
log_error!("Root {} isnt a valid directory", root.display());
|
|
std::process::exit(1);
|
|
}
|
|
|
|
// moved num_cpus from server.rs to main.rs
|
|
let threads = args.threads.unwrap_or_else(|| {
|
|
std::thread::available_parallelism()
|
|
.map(|n| n.get() * 2)
|
|
.unwrap_or(8)
|
|
});
|
|
|
|
if let Err(_) = server::run(root, args.port, threads) {
|
|
log_error!("port {} in use!", args.port);
|
|
}
|
|
|
|
}
|