mirror of
https://github.com/tokio-rs/axum.git
synced 2026-08-22 00:00:17 +02:00
Add serve function and remove Server re-export (#1868)
This commit is contained in:
@@ -6,7 +6,6 @@
|
||||
|
||||
use axum::{extract::Form, response::Html, routing::get, Router};
|
||||
use serde::Deserialize;
|
||||
use std::net::SocketAddr;
|
||||
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
|
||||
|
||||
#[tokio::main]
|
||||
@@ -22,13 +21,12 @@ async fn main() {
|
||||
// build our application with some routes
|
||||
let app = Router::new().route("/", get(show_form).post(accept_form));
|
||||
|
||||
// run it with hyper
|
||||
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
|
||||
tracing::debug!("listening on {}", addr);
|
||||
axum::Server::bind(&addr)
|
||||
.serve(app.into_make_service())
|
||||
// run it
|
||||
let listener = tokio::net::TcpListener::bind("127.0.0.1:3000")
|
||||
.await
|
||||
.unwrap();
|
||||
tracing::debug!("listening on {}", listener.local_addr().unwrap());
|
||||
axum::serve(listener, app).await.unwrap();
|
||||
}
|
||||
|
||||
async fn show_form() -> Html<&'static str> {
|
||||
|
||||
Reference in New Issue
Block a user