-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1a68546
commit dfafcbd
Showing
7 changed files
with
112 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
//! Run with `cargo run --example from_std_listener` command. | ||
//! | ||
//! To connect through browser, navigate to "http://localhost:3000" url. | ||
use axum::{routing::get, Router}; | ||
use std::net::{SocketAddr, TcpListener}; | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
let app = Router::new().route("/", get(|| async { "Hello, world!" })); | ||
|
||
let addr = SocketAddr::from(([127, 0, 0, 1], 3000)); | ||
let listener = TcpListener::bind(addr).unwrap(); | ||
println!("listening on {}", addr); | ||
axum_server::from_tcp(listener) | ||
.serve(app.into_make_service()) | ||
.await | ||
.unwrap(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
//! Run with `cargo run --all-features --example from_std_listener_rustls` | ||
//! command. | ||
//! | ||
//! To connect through browser, navigate to "https://localhost:3000" url. | ||
use axum::{routing::get, Router}; | ||
use axum_server::tls_rustls::RustlsConfig; | ||
use std::net::{SocketAddr, TcpListener}; | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
let app = Router::new().route("/", get(|| async { "Hello, world!" })); | ||
|
||
let config = RustlsConfig::from_pem_file( | ||
"examples/self-signed-certs/cert.pem", | ||
"examples/self-signed-certs/key.pem", | ||
) | ||
.await | ||
.unwrap(); | ||
|
||
let addr = SocketAddr::from(([127, 0, 0, 1], 3000)); | ||
let listener = TcpListener::bind(addr).unwrap(); | ||
println!("listening on {}", addr); | ||
axum_server::from_tcp_rustls(listener, config) | ||
.serve(app.into_make_service()) | ||
.await | ||
.unwrap(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters