Following crate seems easy to use.
https://docs.rs/hyper-reverse-proxy/0.4.0/hyper_reverse_proxy/
sozu is difficult to build in windows, and a bit old (2018).
if we use this, existing server app running in Glassfish can be moved to Rust based server without affecting the client side application. For instance, db related server side code can be migrated to Rust base server.
extern crate hyper;
extern crate futures;
use hyper::server::conn::AddrStream;
use hyper::{Body, Request, Server};
use hyper::service::{service_fn, make_service_fn};
use futures::future::{Future};
fn main() {
// This is our socket address...
let addr = ([127, 0, 0, 1], 13900).into();
// A `Service` is needed for every connection.
let make_svc = make_service_fn(|socket: &AddrStream| {
let remote_addr = socket.remote_addr();
service_fn(move |req: Request<body>| { // returns BoxFut
println!("path: {}, ip: {}", req.uri().path(), remote_addr.ip());
return hyper_reverse_proxy::call(remote_addr.ip(), "http://127.0.0.1:8080", req)
})
});
let server = Server::bind(&addr)
.serve(make_svc)
.map_err(|e| eprintln!("server error: {}", e));
println!("Running server on {:?}", addr);
// Run this server for... forever!
hyper::rt::run(server);
}
No comments:
Post a Comment