initial commit
This commit is contained in:
57
src/bin/server.rs
Normal file
57
src/bin/server.rs
Normal file
@ -0,0 +1,57 @@
|
||||
use clap::Parser;
|
||||
|
||||
#[derive(clap::Parser)]
|
||||
#[command(author, version, about, long_about = None)]
|
||||
struct Opts {
|
||||
#[command(subcommand)]
|
||||
subcommand: Option<Subcommand>,
|
||||
}
|
||||
|
||||
#[derive(clap::Subcommand)]
|
||||
enum Subcommand {
|
||||
Serve {
|
||||
#[clap(long, short = 'l', default_value = "127.0.0.1", env)]
|
||||
listen_address: String,
|
||||
#[clap(long, short = 'p', default_value = "3000", env)]
|
||||
listen_port: u16,
|
||||
},
|
||||
|
||||
#[cfg(feature = "extract-static")]
|
||||
Extract { destination: String },
|
||||
}
|
||||
|
||||
impl Default for Subcommand {
|
||||
fn default() -> Self {
|
||||
Subcommand::Serve {
|
||||
listen_address: "127.0.0.1".into(),
|
||||
listen_port: 3000,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let opts = Opts::parse();
|
||||
|
||||
tracing_subscriber::fmt::init();
|
||||
|
||||
match opts.subcommand.unwrap_or_default() {
|
||||
Subcommand::Serve {
|
||||
listen_address,
|
||||
listen_port,
|
||||
} => {
|
||||
let service = hello::web::routes::make_service()?;
|
||||
tracing::info!(listen_address, listen_port, "app is service");
|
||||
let listener =
|
||||
tokio::net::TcpListener::bind(format!("{listen_address}:{listen_port}")).await?;
|
||||
axum::serve(listener, service).await?;
|
||||
}
|
||||
|
||||
#[cfg(feature = "extract-static")]
|
||||
Subcommand::Extract { destination } => {
|
||||
staticfiles::extract(destination).await?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
Reference in New Issue
Block a user