Skip to content

Instantly share code, notes, and snippets.

@terry90
Last active June 21, 2019 16:27
Show Gist options
  • Save terry90/83c00407b17ff0388bfe4a7bea83c251 to your computer and use it in GitHub Desktop.
Save terry90/83c00407b17ff0388bfe4a7bea83c251 to your computer and use it in GitHub Desktop.
rs-simple-proxy usage
extern crate simple_proxy;
mod middlewares;
use middlewares::auth::Auth;
use simple_proxy::middlewares::{Cors, Health, Logger, Router};
use simple_proxy::SimpleProxy;
fn main() {
let config = config::Config::new();
let mut proxy = SimpleProxy::new(config.port, config.environment);
// 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();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment