httpd: Use `State` instead of `Extension` for `root_handler`

Signed-off-by: xphoniex <dj.2dixx@gmail.com>
This commit is contained in:
xphoniex 2023-02-16 15:51:31 +00:00
parent 6ca1c89610
commit 2606372a14
No known key found for this signature in database
GPG Key ID: 9FACFECE1E3B3994
1 changed files with 4 additions and 3 deletions

View File

@ -4,11 +4,12 @@ use std::collections::HashMap;
use std::sync::Arc;
use std::time::Duration;
use axum::extract::State;
use axum::http::header::{AUTHORIZATION, CONTENT_TYPE};
use axum::http::Method;
use axum::response::{IntoResponse, Json};
use axum::routing::get;
use axum::{Extension, Router};
use axum::Router;
use serde::{Deserialize, Serialize};
use serde_json::json;
use tokio::sync::RwLock;
@ -78,7 +79,7 @@ impl Context {
pub fn router(ctx: Context) -> Router {
let root_router = Router::new()
.route("/", get(root_handler))
.layer(Extension(ctx.clone()));
.with_state(ctx.clone());
Router::new()
.merge(root_router)
@ -98,7 +99,7 @@ pub fn router(ctx: Context) -> Router {
)
}
async fn root_handler(Extension(ctx): Extension<Context>) -> impl IntoResponse {
async fn root_handler(State(ctx): State<Context>) -> impl IntoResponse {
let response = json!({
"message": "Welcome!",
"service": "radicle-httpd",