From d631223849e5c5d290a11298125b0458c7b50c0d Mon Sep 17 00:00:00 2001 From: Zach Duey Date: Sat, 18 Apr 2026 14:56:45 -0500 Subject: [PATCH] fix how link sharing works by deriving the base url --- apps/kitchen_mate/Dockerfile | 2 +- apps/kitchen_mate/src/kitchen_mate/config.py | 3 --- apps/kitchen_mate/src/kitchen_mate/routes/sharing.py | 9 +++++---- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/apps/kitchen_mate/Dockerfile b/apps/kitchen_mate/Dockerfile index d99ad1d..55f6523 100644 --- a/apps/kitchen_mate/Dockerfile +++ b/apps/kitchen_mate/Dockerfile @@ -68,4 +68,4 @@ ENV STORAGE_LOCAL_PATH=/data/uploads EXPOSE $PORT # Run migrations and start the application (shell form to expand $PORT) -CMD uv run alembic upgrade head && uv run uvicorn kitchen_mate.main:app --host 0.0.0.0 --port $PORT +CMD uv run alembic upgrade head && uv run uvicorn kitchen_mate.main:app --host 0.0.0.0 --port $PORT --proxy-headers --forwarded-allow-ips="*" diff --git a/apps/kitchen_mate/src/kitchen_mate/config.py b/apps/kitchen_mate/src/kitchen_mate/config.py index 6aee9b7..72e121c 100644 --- a/apps/kitchen_mate/src/kitchen_mate/config.py +++ b/apps/kitchen_mate/src/kitchen_mate/config.py @@ -79,9 +79,6 @@ class Settings(BaseSettings): # CORS configuration cors_origins: str = "http://localhost:5173" - # Base URL for constructing shareable links - app_base_url: str = "http://localhost:5173" - # Database configuration cache_db_path: str = "kitchenmate.db" cache_enabled: bool = True diff --git a/apps/kitchen_mate/src/kitchen_mate/routes/sharing.py b/apps/kitchen_mate/src/kitchen_mate/routes/sharing.py index 878c1fa..6d9ba9c 100644 --- a/apps/kitchen_mate/src/kitchen_mate/routes/sharing.py +++ b/apps/kitchen_mate/src/kitchen_mate/routes/sharing.py @@ -4,10 +4,9 @@ from typing import Annotated -from fastapi import APIRouter, Depends, HTTPException +from fastapi import APIRouter, Depends, HTTPException, Request from kitchen_mate.auth import User, get_user -from kitchen_mate.config import Settings, get_settings from kitchen_mate.database.repositories import ( create_or_get_share, get_share_by_token, @@ -17,14 +16,15 @@ ) from kitchen_mate.schemas import CreateShareResponse, SaveSharedRecipeResponse, SharedRecipeResponse + router = APIRouter() @router.post("/me/recipes/{recipe_id}/share", response_model=CreateShareResponse) async def create_share( recipe_id: str, + request: Request, user: Annotated[User, Depends(get_user)], - settings: Annotated[Settings, Depends(get_settings)], ) -> CreateShareResponse: """Generate a shareable link for a recipe.""" try: @@ -32,7 +32,8 @@ async def create_share( except ValueError: raise HTTPException(status_code=404, detail="Recipe not found") - share_url = f"{settings.app_base_url}/shared/{share.share_token}" + base_url = f"{request.url.scheme}://{request.url.netloc}" + share_url = f"{base_url}/shared/{share.share_token}" return CreateShareResponse( share_token=share.share_token, share_url=share_url,