
* actix-web 1.0.0 brought some changes in how associated data is accessed, and how handlers are written. * static files are now a separate crate `actix-files`. * web::run now creates the App and the Server and runs the server. they really want to have HttpServer::new and App::new in the same scope (I couldn't find a proper signature for the create_app function) * replace .trim_right_matches (depreceated in rust 1.33) with .trim_end_matches https://github.com/actix/actix-web/blob/web-v1.0.0/MIGRATION.md
40 lines
1.5 KiB
Rust
40 lines
1.5 KiB
Rust
mod channel;
|
|
mod web;
|
|
|
|
fn main() -> std::io::Result<()> {
|
|
let app = clap::App::new(clap::crate_name!())
|
|
.author(clap::crate_authors!("\n"))
|
|
.version(clap::crate_version!())
|
|
.about(clap::crate_description!())
|
|
.arg(clap::Arg::with_name("chdir")
|
|
.long("chdir")
|
|
.value_name("DIRECTORY")
|
|
.help("Specify directory to server")
|
|
.default_value(".")
|
|
.takes_value(true))
|
|
.arg(clap::Arg::with_name("addr")
|
|
.long("bind")
|
|
.value_name("ADDRESS")
|
|
.help("Specify alternate bind address")
|
|
.default_value("0.0.0.0")
|
|
.takes_value(true))
|
|
.arg(clap::Arg::with_name("port")
|
|
.value_name("PORT")
|
|
.help("Specify alternate port")
|
|
.default_value("8000")
|
|
.index(1));
|
|
let matches = app.get_matches();
|
|
|
|
let chdir = matches.value_of("chdir").unwrap(); // these shouldn't panic ever, since all have default_value
|
|
let addr = matches.value_of("addr").unwrap();
|
|
let port = matches.value_of("port").unwrap();
|
|
let bind_addr = format!("{}:{}", addr, port);
|
|
|
|
std::env::set_var("RUST_LOG", std::env::var("RUST_LOG").unwrap_or("info".to_string()));
|
|
env_logger::init();
|
|
|
|
let root = std::path::PathBuf::from(chdir).canonicalize()?;
|
|
std::env::set_current_dir(&root)?;
|
|
|
|
web::run(&bind_addr, &root)
|
|
}
|