summaryrefslogtreecommitdiffstats
path: root/src/routes.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/routes.rs')
-rw-r--r--src/routes.rs22
1 files changed, 7 insertions, 15 deletions
diff --git a/src/routes.rs b/src/routes.rs
index ad00b1e..39a0976 100644
--- a/src/routes.rs
+++ b/src/routes.rs
@@ -1,34 +1,27 @@
-use std::sync::Arc;
-
use axum::{
http::{StatusCode, Uri},
- middleware::map_request_with_state,
response::IntoResponse,
};
use axum_extra::routing::RouterExt;
-use tower_http::cors::CorsLayer;
+use tower_http::{cors::CorsLayer, trace::TraceLayer};
use crate::state::AppState;
-use self::jwt::authenticate;
-
mod healthcheck;
mod jwt;
-mod login;
mod register;
mod user;
#[tracing::instrument]
-pub fn init_router(state: Arc<AppState>) -> axum::Router {
+pub fn init_router(state: AppState) -> axum::Router {
axum::Router::new()
.typed_get(user::User::get)
- .typed_get(login::Logout::get)
- .route_layer(map_request_with_state(state.clone(), authenticate))
.typed_get(healthcheck::HealthCheck::get)
.typed_get(user::UserUuid::get)
.typed_post(register::Register::post)
- .typed_post(login::Login::post)
+ .nest("/api/auth", jwt::init_router(state.clone()))
.layer(CorsLayer::permissive())
+ .layer(TraceLayer::new_for_http())
.fallback(fallback)
.with_state(state)
}
@@ -54,10 +47,9 @@ mod tests {
#[sqlx::test]
async fn test_route_not_found(pool: PgPool) -> TestResult {
- let state = Arc::new(AppState {
- pool,
- jwt_secret: JWT_SECRET.to_string(),
- });
+ std::env::set_var("JWT_SECRET", JWT_SECRET);
+
+ let state = AppState { pool };
let router = init_router(state.clone());
let request = Request::builder()