From 5b977aa0429042e494da649b3ca7e40e78549ad1 Mon Sep 17 00:00:00 2001 From: L-Nafaryus Date: Wed, 20 Mar 2024 01:37:00 +0500 Subject: [PATCH] backend: fix default address for cookies --- src/config.rs | 2 +- src/main.rs | 21 +++++++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/config.rs b/src/config.rs index 0387ff2..d247365 100644 --- a/src/config.rs +++ b/src/config.rs @@ -46,7 +46,7 @@ impl Config { name: env::var("DATABASE_NAME").unwrap_or("elnafo".to_string()), }, server: Server { - address: env::var("SERVER_ADDRESS").unwrap_or("0.0.0.0".to_string()), + address: env::var("SERVER_ADDRESS").unwrap_or("127.0.0.1".to_string()), port: env::var("SERVER_PORT") .unwrap_or("54600".to_string()) .parse() diff --git a/src/main.rs b/src/main.rs index 8c0e44e..4ebb581 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,9 +5,9 @@ pub mod error_handle; pub mod state; use axum::{ - extract::State, + extract::{Path, State}, http::{ - header::{ACCEPT, AUTHORIZATION, CONTENT_TYPE, ORIGIN}, + header::{ACCEPT, AUTHORIZATION, CONTENT_TYPE, COOKIE, ORIGIN}, HeaderValue, Method, StatusCode, Uri, }, middleware, @@ -65,8 +65,11 @@ async fn main() { let cors = CorsLayer::new() .allow_methods([Method::GET, Method::POST, Method::OPTIONS]) - .allow_headers(vec![ORIGIN, AUTHORIZATION, ACCEPT, CONTENT_TYPE]) - .allow_origin("http://0.0.0.0:54600".parse::().unwrap()) //Any) + .allow_headers(vec![ORIGIN, AUTHORIZATION, ACCEPT, CONTENT_TYPE, COOKIE]) + .allow_origin([ + "http://localhost:54600".parse().unwrap(), + "http://localhost:5173".parse().unwrap(), + ]) //Any) .allow_credentials(true); //"http://localhost:5173".parse::().unwrap()); let app = Router::new() @@ -75,10 +78,6 @@ async fn main() { .route("/assets/*file", get(static_handler)) .route("/api/v1/register_user", post(api::v1::register_user)) .route("/api/v1/login_user", post(api::v1::login_user)) - .layer(cors) - .route("/api/v1/healthcheck", get(api::v1::healthcheck)) - .route("/api/v1/users", get(users)) - .route("/api/v1/logout_user", get(api::v1::logout_user)) .route( "/api/v1/me", get(api::v1::me).route_layer(middleware::from_fn_with_state( @@ -86,6 +85,10 @@ async fn main() { api::v1::jwt_auth, )), ) + .layer(cors) + .route("/api/v1/healthcheck", get(api::v1::healthcheck)) + .route("/api/v1/users", get(users)) + .route("/api/v1/logout_user", get(api::v1::logout_user)) .layer( TraceLayer::new_for_http() .make_span_with(trace::DefaultMakeSpan::new().level(Level::INFO)) @@ -109,6 +112,8 @@ async fn user_login() -> impl IntoResponse { frontend::BaseTemplate { view: "signin" } } +async fn user(Path(user): Path) -> impl IntoResponse {} + async fn users( State(state): State>, ) -> Result>, (StatusCode, Json)> {