```rust extern crate simple_proxy;
mod middlewares;
use middlewares::auth::Auth; use simpleproxy::middlewares::{Cors, Health, Logger, Router}; use simpleproxy::SimpleProxy;
fn main() { // Middlewares let auth = Auth::new(config.clone()); let health = Health::new("/health", "OK !"); let router = Router::new(config); let logger = Logger::new(); let cors = Cors::new( "*", "GET, POST, PATCH, DELETE, OPTIONS", "Content-Type, Accept, Authorization, X-Requested-Ids, X-Tenant", );
// Order matters
proxy.add_middleware(Box::new(logger));
proxy.add_middleware(Box::new(cors));
proxy.add_middleware(Box::new(health));
proxy.add_middleware(Box::new(router));
proxy.add_middleware(Box::new(auth));
// Start proxy
proxy.run();
}
```
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