```rust use simpleproxy::middlewares::{router::*, Logger}; use simpleproxy::{Environment, SimpleProxy};
use structopt::StructOpt;
struct Cli { port: u16, }
pub struct Config();
impl RouterConfig for Config { fn getrouterfilename(&self) -> &'static str { "routes.json" } }
async fn main() { let args = Cli::from_args();
let mut proxy = SimpleProxy::new(args.port, Environment::Development);
let logger = Logger::new();
let router = Router::new(&Config());
// Order matters
proxy.add_middleware(Box::new(router));
proxy.add_middleware(Box::new(logger));
// Start proxy
let _ = proxy.run().await;
} ```
You can create your custom middleware by creating a struct implementing Middleware, consisting of 4 callbacks:
before_request
will be run every timerequest_failure
will be run when the request failsrequest_success
will be run when the request succeeds, you can then handle the response according to the status code or the bodyafter_request
will be run every time