Skip to content

Commit 61eb097

Browse files
Intermediate commit: removed RabbitMQ and used Redis as a broker, removed nginx by now
1 parent bfc162f commit 61eb097

File tree

6 files changed

+39
-117
lines changed

6 files changed

+39
-117
lines changed

config/nginx/default.conf

Lines changed: 0 additions & 41 deletions
This file was deleted.

config/nginx/default.conf.template

Lines changed: 0 additions & 41 deletions
This file was deleted.

docker-compose.yml

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,11 @@ services:
2424
ports:
2525
- "6379:6379"
2626

27-
rabbitmq:
28-
image: rabbitmq:3-management
29-
container_name: broker
30-
restart: always
31-
ports:
32-
- "15672:15672"
33-
- "5672:5672"
34-
env_file:
35-
- .env
36-
healthcheck:
37-
test: [ "CMD", "rabbitmq-diagnostics", "ping" ]
38-
interval: 10s
39-
timeout: 5s
40-
retries: 3
41-
4227
web:
4328
build: .
4429
container_name: backend
4530
command: [ "./wait-for-it.sh", "database:5432", "--",
46-
"sh", "-c", "python manage.py migrate && python manage.py collectstatic --noinput && ls -l /code/staticfiles/ && uvicorn ecommerce_api.asgi:application --host 0.0.0.0 --port 8000 --reload" ]
31+
"sh", "-c", "python manage.py migrate && python manage.py collectstatic --noinput && uvicorn ecommerce_api.asgi:application --host 0.0.0.0 --port 8000 --reload" ]
4732
restart: always
4833
volumes:
4934
- .:/code
@@ -55,21 +40,8 @@ services:
5540
- .env
5641
depends_on:
5742
- cache
58-
- rabbitmq
5943
- database
6044

61-
nginx:
62-
image: nginx:1.27.4
63-
container_name: nginx
64-
restart: always
65-
volumes:
66-
- ./config/nginx/default.conf:/etc/nginx/conf.d/default.conf
67-
- .:/code
68-
ports:
69-
- "80:80"
70-
command: [ "/code/wait-for-it.sh", "web:8000", "--", "nginx", "-g", "daemon off;" ]
71-
depends_on:
72-
- web
7345

7446
volumes:
7547
database:

ecommerce_api/settings/base.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -414,20 +414,29 @@
414414

415415
TAGGIT_CASE_INSENSITIVE = True
416416

417-
CELERY_BROKER_URL = f"amqp://{config('RABBITMQ_DEFAULT_USER')}:{config('RABBITMQ_DEFAULT_PASS')}@{config('RABBITMQ_HOST')}:5672/"
417+
# Celery Configuration using Redis
418+
CELERY_BROKER_URL = f"redis://{config('REDIS_HOST', default='cache')}:{config('REDIS_PORT', default='6379')}/0"
419+
CELERY_RESULT_BACKEND = f"redis://{config('REDIS_HOST', default='cache')}:{config('REDIS_PORT', default='6379')}/0"
420+
CELERY_ACCEPT_CONTENT = ['json']
421+
CELERY_TASK_SERIALIZER = 'json'
422+
CELERY_RESULT_SERIALIZER = 'json'
423+
CELERY_TIMEZONE = 'UTC'
418424

419425
SESSION_ENGINE = "django.contrib.sessions.backends.cache"
420426
SESSION_CACHE_ALIAS = "default"
421427

422-
# Session cookie settings for React frontend
423-
SESSION_COOKIE_SAMESITE = 'None'
428+
# Session cookie settings - Fixed for admin compatibility
429+
SESSION_COOKIE_SAMESITE = 'Lax' # Changed from 'None' to 'Lax' for admin compatibility
424430
SESSION_COOKIE_SECURE = False # Set to True in production with HTTPS
425-
SESSION_COOKIE_HTTPONLY = False
431+
SESSION_COOKIE_HTTPONLY = True # Changed to True for security and admin compatibility
426432
SESSION_COOKIE_AGE = 1209600 # 2 weeks
433+
SESSION_SAVE_EVERY_REQUEST = True # Ensure sessions are saved on every request
427434

428-
# CSRF settings for API
429-
CSRF_COOKIE_SAMESITE = 'None'
435+
# CSRF settings - Updated for better compatibility
436+
CSRF_COOKIE_SAMESITE = 'Lax' # Changed from 'None' to 'Lax'
430437
CSRF_COOKIE_SECURE = False # Set to True in production with HTTPS
438+
CSRF_COOKIE_HTTPONLY = False # Explicitly set for compatibility
431439
CSRF_TRUSTED_ORIGINS = [
432440
'http://localhost:3000',
441+
'http://localhost:8000', # Added for admin access
433442
]

ecommerce_api/urls.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818
from django.conf import settings
1919
from django.contrib import admin
2020
from django.contrib.sitemaps.views import sitemap
21+
from django.http import JsonResponse
2122
from django.urls import path, include
23+
from django.views.decorators.csrf import csrf_exempt
24+
from django.views.decorators.http import require_http_methods
2225
from drf_spectacular.views import SpectacularAPIView, SpectacularRedocView, SpectacularSwaggerView
2326

2427
from shop.feeds import TrendingProductsFeed
@@ -28,7 +31,26 @@
2831
'products': ProductSitemap,
2932
}
3033

34+
35+
@require_http_methods(["GET"])
36+
def api_root(request):
37+
"""Root API endpoint that provides information about available endpoints"""
38+
return JsonResponse({
39+
'message': 'E-commerce API',
40+
'version': '1.0',
41+
'status': 'healthy',
42+
'endpoints': {
43+
'auth': '/auth/',
44+
'api': '/api/v1/',
45+
'admin': '/admin/',
46+
'payment': '/payment/',
47+
'docs': '/api/schema/swagger-ui/',
48+
}
49+
})
50+
51+
3152
urlpatterns = [
53+
path('', api_root, name='api-root'), # Handle root path requests
3254
path('auth/', include('account.urls', namespace='auth')),
3355
path('api/schema/', SpectacularAPIView.as_view(), name='schema'),
3456
path('api/schema/swagger-ui/', SpectacularSwaggerView.as_view(url_name='schema'), name='swagger-ui'),
@@ -52,3 +74,4 @@
5274
from django.conf.urls.static import static
5375

5476
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
77+
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

requirements.txt

-20 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)