How can I make a websocket server in axum that accepts secure connections? Currently I just have something that's mostly copied from the chat example:
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let app = Router::new().route("/websocket", get(websocket_handler));
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
Server::bind(&addr)
.serve(app.into_make_service_with_connect_info::<SocketAddr>())
.await?;
Ok(())
}
async fn websocket_handler(
ws: WebSocketUpgrade,
ConnectInfo(ip_address): ConnectInfo<SocketAddr>,
) -> impl IntoResponse {
ws.on_upgrade(move |socket| {
let (sender, receiver) = socket.split();
let user = UserWithSocket {
user: User::Uninitialized,
sender,
receiver,
ip_address,
};
websocket(user)
})
}
async fn websocket(mut user: UserWithSocket) {
println!("{} connected", user.ip_address);
while let Some(Ok(msg)) = user.receiver.next().await {
if process_websocket_message(msg, &mut user).await.is_break() {
break;
}
}
println!("{} disconnected", user.ip_address);
}
and it works fine when I try to connect to ws://127.0.0.1:3000/websocket but if I try to use a secure connection by changing ws to wss then I can't connect. How can I allow secure connections? I can't find anything about this anywhere online or in the documentation