Fix hardcoded localhost:8000 URLs
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
- Add backend/utils.py for URL management - Update serializers to use normalize_file_url() - Update views to use URL utils from env vars - Fix frontend components to use NEXT_PUBLIC_API_URL - Add new env vars: DJANGO_BACKEND_URL, DJANGO_MEDIA_BASE_URL - Replace all hardcoded localhost:8000 with configurable URLs
This commit is contained in:
@@ -4,6 +4,7 @@ from rest_framework.permissions import IsAuthenticated
|
||||
from rest_framework.response import Response
|
||||
from rest_framework import serializers
|
||||
from django.contrib.auth import get_user_model
|
||||
from backend.utils import normalize_file_url
|
||||
|
||||
User = get_user_model()
|
||||
|
||||
@@ -22,18 +23,16 @@ class UserProfileSerializer(serializers.ModelSerializer):
|
||||
if obj.avatar:
|
||||
request = self.context.get('request')
|
||||
if request:
|
||||
# Заменяем внутренний Docker URL на localhost для клиента
|
||||
absolute_uri = request.build_absolute_uri(obj.avatar.url)
|
||||
return absolute_uri.replace('http://web:8000', 'http://localhost:8000')
|
||||
return normalize_file_url(absolute_uri)
|
||||
return None
|
||||
|
||||
def get_cover_url(self, obj):
|
||||
if obj.cover:
|
||||
request = self.context.get('request')
|
||||
if request:
|
||||
# Заменяем внутренний Docker URL на localhost для клиента
|
||||
absolute_uri = request.build_absolute_uri(obj.cover.url)
|
||||
return absolute_uri.replace('http://web:8000', 'http://localhost:8000')
|
||||
return normalize_file_url(absolute_uri)
|
||||
return None
|
||||
|
||||
@api_view(['GET', 'PUT', 'PATCH'])
|
||||
|
||||
Reference in New Issue
Block a user