#[cfg(target_env = "musl")]
#[global_allocator]
static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
use clap::Parser;
use httpcan::config::Args;
use httpcan::{HttpCanServer, ServerConfig};
#[actix_web::main]
async fn main() -> std::io::Result<()> {
dotenvy::dotenv().ok();
if std::env::var("HTTPCAN_VERSION").is_err() {
std::env::set_var("HTTPCAN_VERSION", env!("CARGO_PKG_VERSION"));
}
httpcan::logging::init();
let args = Args::parse();
let exclude_headers: Vec<String> = args
.exclude_headers
.map(|headers_str| {
headers_str
.split(',')
.map(|s| s.trim().to_lowercase())
.filter(|s| !s.is_empty())
.collect()
})
.unwrap_or_default();
let oauth2_clients = args.oauth2_clients.map(|spec| {
spec.split(',')
.map(str::trim)
.filter(|entry| !entry.is_empty())
.map(|entry| match entry.split_once(':') {
Some((id, secret)) => (id.trim().to_string(), secret.trim().to_string()),
None => {
eprintln!("invalid --oauth2-clients entry (expected ID:SECRET): {entry}");
std::process::exit(2);
}
})
.collect()
});
let mut config = ServerConfig::new()
.port(args.port)
.add_current_server(args.openapi_servers.add_current_server())
.exclude_headers(exclude_headers)
.max_bytes(args.max_bytes)
.canonical_scheme(args.canonical_scheme)
.oauth2_clients(oauth2_clients);
if let Some(dir) = args.static_dir {
config = config.static_dir(dir);
}
HttpCanServer::with_config(config).run().await
}