Fix hardcoded localhost:8000 URLs
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:
2025-11-08 19:25:35 +09:00
parent fb74a4a25d
commit e82f0f8e6f
17 changed files with 1396 additions and 58 deletions

View File

@@ -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'])