diff --git a/config/logstash.conf b/config/logstash.conf index 329a522..26c681a 100644 --- a/config/logstash.conf +++ b/config/logstash.conf @@ -25,4 +25,4 @@ output { index => "django-logs-%{+YYYY.MM.dd}" } stdout { codec => rubydebug } - } +} diff --git a/config/nginx.conf b/config/nginx.conf index f4a2e02..3703d9a 100644 --- a/config/nginx.conf +++ b/config/nginx.conf @@ -1,16 +1,16 @@ server { listen 80; - server_name localhost; + server_name localhost ft-transcendence.com www.ft-transcendence.com; # Redirect HTTP to HTTPS location / { - return 301 https://localhost:1443$request_uri; + return 301 https://www.ft-transcendence.com:1443$request_uri; } } server { listen 443 ssl; - server_name localhost; + server_name localhost ft-transcendence.com www.ft-transcendence.com; ssl_certificate /etc/nginx/ssl/certificate.crt; ssl_certificate_key /etc/nginx/ssl/private.key; diff --git a/config/ssl.conf b/config/ssl.conf index 7b95607..a9518a2 100644 --- a/config/ssl.conf +++ b/config/ssl.conf @@ -19,6 +19,6 @@ extendedKeyUsage = serverAuth [alt_names] DNS.1 = localhost -DNS.2 = www.ft_transcendence.com -DNS.3 = ft_transcendence.com +DNS.2 = www.ft-transcendence.com +DNS.3 = ft-transcendence.com IP.1 = 127.0.0.1 diff --git a/docker-compose-elk.yml b/docker-compose-elk.yml index 6075abf..3f50acc 100644 --- a/docker-compose-elk.yml +++ b/docker-compose-elk.yml @@ -167,14 +167,12 @@ services: volumes: pong_django_logs: + external: true + name: shared_pong_django_logs pong_es_data_01: - driver: local pong_kibana: - driver: local pong_logstash_data01: - driver: local certs: - driver: local networks: app-network: diff --git a/docker-compose.yml b/docker-compose.yml index d247437..4556492 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -79,9 +79,8 @@ volumes: device: ${PROJECT_PATH} o: bind pong_django_logs: - driver: local + name: shared_pong_django_logs pong_pg_data: - driver: local networks: diff --git a/makefile b/makefile index 5ada811..e345267 100644 --- a/makefile +++ b/makefile @@ -9,9 +9,7 @@ ELK_COMPOSE=docker compose -f $(ELK_COMPOSE_FILE) -p $(ELK_PROJECT_NAME) CONTAINER=$(c) - # Define a red color variable using ANSI escape code -RED=\033[31m GREEN=\033[32m NC=\033[0m # No Color (reset) @@ -27,6 +25,7 @@ down: destroy: $(COMPOSE) down -v --rmi all + docker image prune -f ssl-certs: @if [ ! -f certs/ssl/private.key ] && [ ! -f certs/ssl/certificate.crt ]; then \ @@ -39,16 +38,22 @@ ssl-certs: echo "$(GREEN)SSL certificates already exist.$(NC)"; \ fi -# Manage ELK stack +edit-hosts: + @echo "Checking and adding domains to /etc/hosts if they don't exist..." + @sudo sh -c 'echo "" >> /etc/hosts' + @sudo sh -c 'grep -q "127.0.0.1 www.ft-transcendence.com" /etc/hosts || echo "127.0.0.1 www.ft-transcendence.com" >> /etc/hosts' + @sudo sh -c 'grep -q "127.0.0.1 ft-transcendence.com" /etc/hosts || echo "127.0.0.1 ft-transcendence.com" >> /etc/hosts' +# Manage ELK stack elk-up: - $(ELK_COMPOSE) up -d --remove-orphans || true + $(ELK_COMPOSE) up -d || true elk-down: - $(ELK_COMPOSE) down --remove-orphans + $(ELK_COMPOSE) down elk-destroy: - $(ELK_COMPOSE) down --remove-orphans -v --rmi all + $(ELK_COMPOSE) down -v --rmi all + docker image prune -f kill-pid: sudo lsof -i :5432 | awk 'NR>1 {print $$2}' | xargs sudo kill -9 || true @@ -70,6 +75,8 @@ help: @echo " make stop [c=service] # Stop containers" @echo " make logs [c=service] # Tail logs of containers" @echo " make ssl-certs # create ssl certificate" + @echo " make edit-hosts # add host to /etc/hosts" + @echo " make help # Show this help" .PHONY: up build start stop down destroy logs ps db-shell help diff --git a/pong/game/urls.py b/pong/game/urls.py index df150f0..b5f6eb0 100644 --- a/pong/game/urls.py +++ b/pong/game/urls.py @@ -14,5 +14,6 @@ urlpatterns = [ path('web3/', views.read_data, name='read_data'), path('api/match_list/', match_list_json, name='match_list_json'), path('api/player_list/', player_list_json, name='player_list_json'), - path('api/tournoi_list/', tournoi_list_json, name='tournoi_list_json') + path('api/tournoi_list/', tournoi_list_json, name='tournoi_list_json'), + path('trigger-error/', views.trigger_error) ] diff --git a/pong/game/views.py b/pong/game/views.py index a09a6a5..49ef32c 100644 --- a/pong/game/views.py +++ b/pong/game/views.py @@ -9,10 +9,14 @@ from django.contrib.auth.models import User from django.contrib.auth import authenticate from django.views.decorators.csrf import csrf_exempt from rest_framework import viewsets +from django.http import HttpResponse import json import uuid +def trigger_error(request): + raise ValueError("This is a test error to generate a 500 response.") + def index(request): return render(request, 'index.html') @@ -172,4 +176,4 @@ def write_data(request): # # Attente de la confirmation de la transaction # tx_receipt = web3.eth.wait_for_transaction_receipt(tx_hash) # print("Transaction receipt:", tx_receipt) - print("-----------------------------") \ No newline at end of file + print("-----------------------------") diff --git a/pong/settings.py b/pong/settings.py index 462d6b1..995d669 100644 --- a/pong/settings.py +++ b/pong/settings.py @@ -22,8 +22,13 @@ SECRET_KEY = '12345678' # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True -ALLOWED_HOSTS = ['*'] +ALLOWED_HOSTS = [ + 'www.ft-transcendence.com', + 'ft-transcendence.com', + 'localhost', + '127.0.0.1'] +USE_X_FORWARDED_HOST = True # Application definition @@ -137,32 +142,6 @@ CHANNEL_LAYERS = { }, } -LOGGING = { - 'version': 1, # Django requires this key - 'disable_existing_loggers': False, # Keep Django's default loggers - 'formatters': { - 'simple': { - 'format': '{levelname} {message}', - 'style': '{', # Allows to use Python's new style string formatting - }, - }, - 'handlers': { - 'console': { # Log to the console - 'level': 'DEBUG', # Minimum level of messages that should be handled - 'class': 'logging.StreamHandler', - 'formatter': 'simple', # Use the simple formatter defined above - }, - }, - 'loggers': { - 'django': { # The main logger for Django itself - 'handlers': ['console'], - 'level': 'DEBUG', # Minimum log level to be logged - 'propagate': False, # Prevents log propagation to other loggers - }, - }, -} - -""" LOGGING = { 'version': 1, # The version of the logging configuration schema 'disable_existing_loggers': False, # Allows existing loggers to keep logging @@ -193,8 +172,7 @@ LOGGING = { 'django': { # The Django logger catches all messages sent by the Django framework 'handlers': ['file', 'console'], # Sends logs to both the file and the console 'level': 'DEBUG', # Minimum log level to be logged - 'propagate': True, # If True, messages will be passed to the parent loggers as well + 'propagate': False, # If True, messages will be passed to the parent loggers as well }, }, } -"""