axum-server icon indicating copy to clipboard operation
axum-server copied to clipboard

Serve same app on http and https

Open hpsjakob opened this issue 1 year ago • 1 comments

Hello,

thanks for developing this very useful crate! I want to run a server that serves the same app with http and https on different ports. I've seen there's an example for running different apps on http and https. I could achieve this by running app.clone():

let a = axum_server::bind_rustls(
    "0.0.0.0:8080".parse().unwrap(),
    tls_config,
)
  .handle(server_handle)
  .serve(app.clone().into_make_service());
let b = axum_server::bind("0.0.0.0:8081".parse().unwrap()).serve(app.into_make_service());
select! {
    _ = a => {},
    _ = b => {}
}

However, this increased the memory usage of the server significantly. So I'm wondering if there is a better way to achieve this? Can someone maybe give me a hint?

hpsjakob avatar Jan 25 '24 09:01 hpsjakob

I just measured the RAM usage again and found that my previous results were not accurate. The clone does not cost measurable more memory.

hpsjakob avatar Jan 26 '24 09:01 hpsjakob

Duplicate of #48.

daxpedda avatar Jul 30 '24 19:07 daxpedda