with tide 0.14 we don't even need h1-server

This commit is contained in:
Jacob Rothstein 2020-10-16 18:30:51 -07:00
parent 253c920f20
commit e902df1040
No known key found for this signature in database
GPG Key ID: C38BA18C6CFE15A5
2 changed files with 24 additions and 28 deletions

View File

@ -12,12 +12,9 @@ keywords = ["tide", "https", "tls"]
categories = ["web-programming::http-server", "web-programming"]
[dependencies]
async-std = { version = "1.6.2", features = ["attributes"] }
tide = { version = "0.13.0", default-features = false, features = ["h1-server"] }
async-std = "1.6.5"
tide = { version = "0.14.0", default-features = false }
async-tls = "0.9.0"
rustls = "0.18.0"
async-h1 = "2.1.0"
async-dup = "1.2.1"
[dev-dependencies]
tide = { version = "0.13.0" }

View File

@ -2,41 +2,40 @@ use std::env;
use tide::prelude::*;
use tide_rustls::TlsListener;
async fn endpoint(req: tide::Request<()>) -> tide::Result {
async fn endpoint(req: tide::Request<()>) -> tide::Result<impl Into<tide::Response>> {
Ok(json!({
"localAddr": req.local_addr().unwrap_or("[unknown]"),
"method": req.method().to_string(),
"url": req.url().to_string()
})
.into())
}))
}
#[async_std::main]
async fn main() -> std::io::Result<()> {
let mut app = tide::new();
app.at("*").all(endpoint);
app.at("/").all(endpoint);
fn main() -> std::io::Result<()> {
async_std::task::block_on(async {
let mut app = tide::new();
app.at("*").all(endpoint);
app.at("/").all(endpoint);
if let (Ok(cert), Ok(key)) = (env::var("TIDE_CERT"), env::var("TIDE_KEY")) {
tide::log::with_level(tide::log::LevelFilter::Info);
app.listen(
TlsListener::build()
.addrs("localhost:4433")
.cert(cert)
.key(key),
)
.await?;
} else {
eprintln!(
"
if let (Ok(cert), Ok(key)) = (env::var("TIDE_CERT"), env::var("TIDE_KEY")) {
app.listen(
TlsListener::build()
.addrs("localhost:4433")
.cert(cert)
.key(key),
)
.await?;
} else {
eprintln!(
"
To run this app locally:
* install https://github.com/FiloSottile/mkcert
* $ mkcert -key-file key.pem -cert-file cert.pem localhost 127.0.0.1 ::1
* $ env TIDE_CERT=cert.pem TIDE_KEY=key.pem cargo run --example hello_tls
* $ curl -v https://localhost:4433/secure
"
);
}
);
}
Ok(())
Ok(())
})
}