feat: axum type 0.7

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
Kasper Juul Hermansen 2023-10-31 22:03:48 +01:00
parent c46bd34e16
commit 21fc2587d4
Signed by: kjuulh
GPG Key ID: 57B6E1465221F912
6 changed files with 364 additions and 195 deletions

520
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -13,8 +13,8 @@ tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
clap = {version = "4.4.7", features = ["derive", "env"]} clap = {version = "4.4.7", features = ["derive", "env"]}
async-trait = {version = "0.1.74", features = []} async-trait = {version = "0.1.74", features = []}
axum = {version = "0.6.20", features = []} axum = { git = "https://github.com/tokio-rs/axum", branch = "main", features = ["macros"] }
axum-extra = {version = "0.8.0", features = ["cookie", "cookie-private"]} axum-extra = {git = "https://github.com/tokio-rs/axum", branch = "main" , features = ["cookie", "cookie-private", "typed-header"]}
axum-sessions = {version = "0.6.1", features = []} axum-sessions = {version = "0.6.1", features = []}
async-sqlx-session = {version = "0.4.0", features = ["pg"]} async-sqlx-session = {version = "0.4.0", features = ["pg"]}

View File

@ -1,16 +1,15 @@
use std::fmt::Display; use std::fmt::Display;
use axum::extract::{FromRef, FromRequestParts, Query, State}; use axum::extract::{FromRef, FromRequestParts, Query, State};
use axum::headers::authorization::Basic;
use axum::headers::{Authorization, Cookie};
use axum::http::request::Parts; use axum::http::request::Parts;
use axum::http::StatusCode; use axum::http::StatusCode;
use axum::response::{ErrorResponse, IntoResponse, Redirect}; use axum::response::{ErrorResponse, IntoResponse, Redirect};
use axum::routing::get; use axum::routing::get;
use axum::{async_trait, Json, RequestPartsExt, Router, TypedHeader}; use axum::{async_trait, Json, RequestPartsExt, Router};
use axum_extra::headers::authorization::Basic;
use axum_extra::headers::{Authorization, Cookie};
use axum_extra::TypedHeader;
use serde::Deserialize; use serde::Deserialize;
use serde_json::json; use serde_json::json;

View File

@ -1,4 +1,4 @@
use std::net::SocketAddr; use std::{net::SocketAddr, str::FromStr};
use axum::{ use axum::{
extract::{FromRef, State}, extract::{FromRef, State},
@ -60,13 +60,10 @@ async fn main() -> anyhow::Result<()> {
.with_state(state) .with_state(state)
.nest("/auth", AuthController::new_router(auth_service).await?); .nest("/auth", AuthController::new_router(auth_service).await?);
let addr = SocketAddr::from(([127, 0, 0, 1], 3001)); let addr = SocketAddr::from_str(&format!("{}:{}", "127.0.0.1", "3000"))?;
println!("listening on: {addr}"); let listener = tokio::net::TcpListener::bind(&addr).await?;
println!("open browser at: http://localhost:3001/auth/zitadel");
axum::Server::bind(&addr) axum::serve(listener, app).await?;
.serve(app.into_make_service())
.await
.unwrap();
Ok(()) Ok(())
} }

View File

@ -1,4 +1,4 @@
use std::net::SocketAddr; use std::{net::SocketAddr, str::FromStr};
use axum::{ use axum::{
extract::{FromRef, State}, extract::{FromRef, State},
@ -58,10 +58,11 @@ async fn main() -> anyhow::Result<()> {
let addr = SocketAddr::from(([127, 0, 0, 1], 3001)); let addr = SocketAddr::from(([127, 0, 0, 1], 3001));
println!("listening on: {addr}"); println!("listening on: {addr}");
println!("open browser at: http://localhost:3001/auth/zitadel"); println!("open browser at: http://localhost:3001/auth/zitadel");
axum::Server::bind(&addr)
.serve(app.into_make_service()) let addr = SocketAddr::from_str(&format!("{}:{}", "127.0.0.1", "3000"))?;
.await let listener = tokio::net::TcpListener::bind(&addr).await?;
.unwrap();
axum::serve(listener, app).await?;
Ok(()) Ok(())
} }