seanmonstar / warp

A super-easy, composable, web server framework for warp speeds.
https://seanmonstar.com/post/176530511587/warp
MIT License
9.59k stars 723 forks source link

Default OS / self signed certificate without create it #1073

Closed thewh1teagle closed 1 year ago

thewh1teagle commented 1 year ago

I would like to spawn a ws server easily with wss support without generate myself the certificate. does it possible?

My code:

use futures::StreamExt;
use futures::FutureExt;
use warp::Filter;

#[tokio::main]
async fn main() {
let echo = warp::path("echo")
        .and(warp::ws())
        .map(|ws: warp::ws::Ws| {
            ws.on_upgrade(|websocket| {
                let (tx, rx) = websocket.split();
                rx.forward(tx).map(|result| {
                    if let Err(e) = result {
                        eprintln!("websocket error: {:?}", e);
                    }
                })
            })
        });

    let current_dir = std::env::current_dir().expect("failed to read current directory");
    let routes = warp::get().and(echo.or(warp::fs::dir(current_dir)));
    warp::serve(routes)
            .tls()
            // .cert_path("cert.pem") // <--- I want to avoide this line
            // .key_path("key.rsa") // <--- I want to avoide this line
            .run(([0, 0, 0, 0], 9231)).await;
}
seanmonstar commented 1 year ago

warp does not have support built-in. You might be able to find something prebuilt. I wouldn't want to add it to warp.