init
This commit is contained in:
@@ -1,13 +1,29 @@
|
||||
use axum::Router;
|
||||
use std::sync::Arc;
|
||||
use axum::{Router, middleware};
|
||||
use crate::app::http::api;
|
||||
use crate::app::http::api::core;
|
||||
use crate::app::http::api::{channel, core, message, server};
|
||||
use crate::app::http::middleware::auth_middleware;
|
||||
use crate::app::http::middleware::auth_middleware::auth_middleware;
|
||||
use crate::db::context::DbContext;
|
||||
|
||||
pub fn configure_routes() -> Router {
|
||||
let api_router = Router::new();
|
||||
#[derive(Clone)]
|
||||
pub struct AppState {
|
||||
db: Arc<DbContext>
|
||||
}
|
||||
|
||||
pub fn configure_routes(db_context: Arc<DbContext>) -> Router {
|
||||
let app_state = Arc::new(AppState {
|
||||
db: db_context.clone()
|
||||
});
|
||||
|
||||
let api_router = Router::new()
|
||||
.nest("/server/", server::routes())
|
||||
.nest("/channel/", channel::routes())
|
||||
.nest("/message/", message::routes())
|
||||
.with_state(app_state);
|
||||
|
||||
Router::new()
|
||||
.merge(core::routes())
|
||||
.nest("/api", api_router )
|
||||
|
||||
.nest("/api", api_router)
|
||||
.layer(middleware::from_fn_with_state(db_context.clone(), auth_middleware))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user