From 35e79de37855d9b7b4168013f0d16406b47ec8b9 Mon Sep 17 00:00:00 2001 From: arrelin Date: Sat, 17 Jan 2026 12:52:07 +0300 Subject: [PATCH] fix --- backend/src/routes/invite_link.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/backend/src/routes/invite_link.rs b/backend/src/routes/invite_link.rs index 9d717f7..401cb11 100644 --- a/backend/src/routes/invite_link.rs +++ b/backend/src/routes/invite_link.rs @@ -1,6 +1,6 @@ use axum::{ extract::{Path, State}, - http::StatusCode, + http::{StatusCode, HeaderMap}, Json, }; use axum_login::AuthSession; @@ -70,6 +70,7 @@ fn model_to_response(model: InviteLinkModel, base_url: &str) -> InviteLinkRespon )] pub async fn create_invite_link( auth_session: AuthSession, + headers: HeaderMap, State(db): State, Json(payload): Json, ) -> Result, StatusCode> { @@ -84,7 +85,11 @@ pub async fn create_invite_link( .await .map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?; - let base_url = std::env::var("FRONTEND_URL").unwrap_or_else(|_| "http://localhost:5173".to_string()); + let base_url = headers + .get("origin") + .and_then(|v| v.to_str().ok()) + .map(|s| s.to_string()) + .unwrap_or_else(|| std::env::var("FRONTEND_URL").unwrap_or_else(|_| "http://localhost:5173".to_string())); Ok(Json(model_to_response(invite, &base_url))) } @@ -101,6 +106,7 @@ pub async fn create_invite_link( )] pub async fn get_my_invite_links( auth_session: AuthSession, + headers: HeaderMap, State(db): State, ) -> Result>, StatusCode> { let user = auth_session.user.ok_or(StatusCode::UNAUTHORIZED)?; @@ -110,7 +116,11 @@ pub async fn get_my_invite_links( .await .map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?; - let base_url = std::env::var("FRONTEND_URL").unwrap_or_else(|_| "http://localhost:5173".to_string()); + let base_url = headers + .get("origin") + .and_then(|v| v.to_str().ok()) + .map(|s| s.to_string()) + .unwrap_or_else(|| std::env::var("FRONTEND_URL").unwrap_or_else(|_| "http://localhost:5173".to_string())); let responses: Vec = invites .into_iter() .map(|i| model_to_response(i, &base_url))