initial commit
This commit is contained in:
commit
8208634a0d
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/target
|
1503
Cargo.lock
generated
Normal file
1503
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
17
Cargo.toml
Normal file
17
Cargo.toml
Normal file
@ -0,0 +1,17 @@
|
||||
[package]
|
||||
name = "expose-dir-via-http"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
actix-web = "4"
|
||||
actix-files = "0.6"
|
||||
num_cpus = "1.16"
|
||||
clap = { version = "4.4.18", features = ["cargo", "derive"] }
|
||||
|
||||
[profile.release]
|
||||
lto = true
|
||||
debug = false
|
||||
strip = true
|
||||
panic = "unwind"
|
||||
codegen-units = 1
|
44
src/main.rs
Normal file
44
src/main.rs
Normal file
@ -0,0 +1,44 @@
|
||||
use actix_web::{App, HttpServer};
|
||||
use std::env;
|
||||
use std::net::IpAddr;
|
||||
use std::net::SocketAddr;
|
||||
|
||||
use clap::{crate_name, crate_version, Parser};
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[clap(name = crate_name!(), version = crate_version!())]
|
||||
struct Args {
|
||||
/// Directory to expose
|
||||
#[clap(default_value = ".")]
|
||||
dir: String,
|
||||
|
||||
/// IP address to use
|
||||
#[clap(default_value = "0.0.0.0")]
|
||||
ip: IpAddr,
|
||||
|
||||
/// Port number to connect
|
||||
#[clap(default_value = "8080")]
|
||||
port: u16,
|
||||
}
|
||||
|
||||
#[actix_web::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
let args = Args::parse();
|
||||
|
||||
let dir = args.dir;
|
||||
let sock = SocketAddr::new(args.ip, args.port);
|
||||
|
||||
println!("Starting HTTP server on {sock} exposing dir {dir}");
|
||||
|
||||
HttpServer::new(move || {
|
||||
App::new().service(
|
||||
actix_files::Files::new("/", dir.clone())
|
||||
.show_files_listing()
|
||||
.prefer_utf8(true),
|
||||
)
|
||||
})
|
||||
.workers(num_cpus::get())
|
||||
.bind(sock)?
|
||||
.run()
|
||||
.await
|
||||
}
|
Loading…
Reference in New Issue
Block a user