2

I need to add to my actix-web instance a route that acts as a simple reverse proxy according to these criteria:

  1. I get a call for GET https://host_1:8000/some_route (please don't mind the HTTPS, I'm not handling SSL in my code)

  2. the reverse proxy (actix-web route) changes it to: http://host_2:1234/some_route

  3. the reverse proxy (actix-web route) returns the response

In Go I'm using this simple code:

reverseProxy := &httputil.ReverseProxy{Director: func(r *http.Request) {
  r.URL.Scheme = "http"
  r.URL.Host = "host_2:1234"
}}

router.Group("/some_route", func(group *Group) {
  group.GET("*", reverseProxy)
})

In Rust I don't understand how to do:

#[actix_web::main]
async fn main() -> std::io::Result<()> {
    HttpServer::new(|| {
        App::new()
            .service(hello)
            .route("/some_route", web::get().wrap(SOME_MIDDLEWARE_HERE?).to(WHAT_HERE?)) // This is the line
    })
    .bind(("127.0.0.1", 8000))?
    .run()
    .await
}
Fred Hors
  • 3,258
  • 3
  • 25
  • 71

0 Answers0