added clap to configure port and interfaces, and fixed nixos module
This commit is contained in:
27
src/main.rs
27
src/main.rs
@@ -1,4 +1,5 @@
|
||||
use axum::{Router, routing::get};
|
||||
use clap::Parser;
|
||||
use lazy_static::lazy_static;
|
||||
use std::sync::Arc;
|
||||
use tera::Tera;
|
||||
@@ -20,12 +21,30 @@ lazy_static! {
|
||||
};
|
||||
}
|
||||
|
||||
#[derive(clap::Parser, Debug)]
|
||||
#[command(author, version, about, long_about = None)]
|
||||
pub struct Cli {
|
||||
/// Port to serve on
|
||||
#[arg(short, long, default_value = "8000")]
|
||||
port: String,
|
||||
|
||||
/// Whether to listen on 0.0.0.0
|
||||
#[arg(short, long)]
|
||||
host: bool,
|
||||
|
||||
/// Verbose mode
|
||||
#[arg(short, long)]
|
||||
verbose: bool,
|
||||
}
|
||||
|
||||
struct AppState {
|
||||
app_name: String,
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
let cli = Cli::parse();
|
||||
|
||||
tracing_subscriber::fmt()
|
||||
.with_max_level(tracing::Level::INFO)
|
||||
.init();
|
||||
@@ -39,12 +58,10 @@ async fn main() -> anyhow::Result<()> {
|
||||
.route("/showcase", get(showcase_handler))
|
||||
.with_state(shared_state);
|
||||
|
||||
let host = false;
|
||||
let port = "8000";
|
||||
let addr = if host {
|
||||
format!("0.0.0.0:{}", port)
|
||||
let addr = if cli.host {
|
||||
format!("0.0.0.0:{}", cli.port)
|
||||
} else {
|
||||
format!("127.0.0.1:{}", port)
|
||||
format!("127.0.0.1:{}", cli.port)
|
||||
};
|
||||
|
||||
let listener = tokio::net::TcpListener::bind(&addr).await?;
|
||||
|
||||
Reference in New Issue
Block a user