diff --git a/Cargo.toml b/Cargo.toml index fa1eb50..0237a86 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,4 +11,15 @@ readme = "README.md" repository = "https://github.com/valorem-labs-inc/hyper-server" version = "1.0.0" -[dependencies] \ No newline at end of file +[dependencies] +http = "1.1.0" +http-body-util = "0.1.2" +hyper = "1.4.1" +hyper-util = { version = "0.1.8", features = ["server", "tokio", "server-auto", "server-graceful"] } +rustls = "0.23.13" +tokio = { version = "1.40.0", features = ["net"] } +tokio-rustls = "0.26.0" +tower = "0.5.1" + +[dev-dependencies] +tokio = { version = "1.40.0", features = ["macros"] } diff --git a/src/lib.rs b/src/lib.rs index e69de29..62e11da 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -0,0 +1,32 @@ +// Crate links: +// - tokio: https://docs.rs/tokio/latest/tokio/ +// - rustls: https://docs.rs/rustls/latest/rustls/ +// - tokio_rustls:https://docs.rs/tokio-rustls/latest/tokio_rustls/ +// - hyper: https://docs.rs/hyper/latest/hyper/ +// - tower: https://docs.rs/tower/latest/tower/ + +// We take a `SocketAddr` to bind the server to a specific address. +// We use `TcpListener` to bind the server to the specified address at the TCP layer. +// We use `rustls` to create a new `ServerConfig` instance. +// We use `tokio_rustls` to create a new `TlsAcceptor` instance. +// We use `hyper_util::server::conn::auto` to create a new `Connection` instance. +// Which then passes requests to a `hyper::service::Service` instance. +// Which then can optionally pass requests to a `tower::Service` instance. +// Behind that can be axum, tower, tonic, +// or any other service that implements the `tower::Service` trait. + +pub struct HyperServer {} + +#[cfg(test)] +mod tests { + use std::net::SocketAddr; + use tokio::net::TcpListener; + + #[tokio::test] + async fn test_server() { + // Get a random port from the OS + let addr = SocketAddr::from(([127, 0, 0, 1], 0)); + // Create a TCP listener bound to the random address + let listener = TcpListener::bind(&addr).await.unwrap(); + } +}