use std::collections::HashMap;
use clamber_web_core::proxy_config::{LocationConfig, LocationType, UpstreamConfig};
use clamber_web_core::{ProxyConfig, ProxyServer};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut upstreams = HashMap::new();
upstreams.insert(
"backend".to_string(),
UpstreamConfig {
servers: vec!["127.0.0.1:3000".to_string()], lb_strategy: "roundrobin".to_string(),
},
);
let locations = vec![
LocationConfig {
path: "/api/".to_string(),
location_type: LocationType::Proxy,
proxy_pass: Some("backend".to_string()), root: None,
index: None,
},
LocationConfig {
path: "/static/".to_string(),
location_type: LocationType::Static,
proxy_pass: None,
root: Some("./static".to_string()), index: Some(vec!["index.html".to_string()]),
},
];
let config = ProxyConfig {
server_name: "example.com".to_string(),
listen: "0.0.0.0:8080".to_string(), ssl: false,
ssl_cert: None,
ssl_key: None,
upstreams,
locations,
};
let mut server = ProxyServer::new(config)?;
println!("Starting proxy server on http://{}", "0.0.0.0:8080");
server.start()?;
Ok(())
}