use trillium_cache::{InMemoryStorage, client::Cache};
use trillium_caching_headers::CachingHeaders;
use trillium_client::Client;
use trillium_proxy::Proxy;
use trillium_smol::{ClientConfig, config};
fn main() {
env_logger::Builder::from_env(
env_logger::Env::default().default_filter_or("trillium_cache=trace"),
)
.init();
let origin = std::env::var("ORIGIN").unwrap_or_else(|_| String::from("http://localhost:8000"));
let port: u16 = std::env::var("PORT")
.ok()
.and_then(|p| p.parse().ok())
.unwrap_or(8080);
let cache = Cache::new(InMemoryStorage::new()).shared();
let proxy_client = Client::new(ClientConfig::new()).with_handler(cache);
let proxy = Proxy::new(proxy_client, origin.as_str()).proxy_not_found();
log::info!("conformance proxy: 127.0.0.1:{port} -> {origin}");
config()
.with_port(port)
.with_host("127.0.0.1")
.without_signals()
.run((CachingHeaders::new(), proxy));
}