diff --git a/home/views/pages.py b/home/views/pages.py index 5f38096..f9a84aa 100644 --- a/home/views/pages.py +++ b/home/views/pages.py @@ -2,10 +2,16 @@ from ._base import * def get_online_characters_count(): - with connections['acore_characters'].cursor() as cursor: - cursor.execute("SELECT COUNT(*) FROM characters WHERE online = 1") - result = cursor.fetchone() - return result[0] if result else 0 + # Si la BD de personajes (AzerothCore) aún no está disponible/poblada, + # no rompemos la portada: devolvemos 0 como hace el context_processor. + try: + with connections['acore_characters'].cursor() as cursor: + cursor.execute("SELECT COUNT(*) FROM characters WHERE online = 1") + result = cursor.fetchone() + return result[0] if result else 0 + except Exception as e: + logger.warning("No se pudo contar personajes en línea: %s", e) + return 0 def check_server_status(host, port): if not host or host == "N/A": return False diff --git a/novawow/settings.py b/novawow/settings.py index 1c98aba..34a89af 100644 --- a/novawow/settings.py +++ b/novawow/settings.py @@ -37,7 +37,7 @@ SECRET_KEY = os.getenv('DJANGO_SECRET_KEY', 'django-insecure-dev-key-change-me') DEBUG = _env_bool('DJANGO_DEBUG', False) if not DEBUG: - ALLOWED_HOSTS = ['novawow.com', 'www.novawow.com', '95.216.107.200', 'localhost', '127.0.0.1'] + ALLOWED_HOSTS = ['nightspire.gg', 'www.nightspire.gg', '217.160.229.24', 'localhost', '127.0.0.1'] SECURE_SSL_REDIRECT = False SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') SECURE_HSTS_SECONDS = 31536000 # Habilita HSTS por 1 año @@ -47,7 +47,7 @@ if not DEBUG: CSRF_COOKIE_SECURE = True else: # Modo desarrollo, no se aplican configuraciones de seguridad - ALLOWED_HOSTS = ['localhost', '127.0.0.1', 'novawow.com', 'www.novawow.com'] + ALLOWED_HOSTS = ['localhost', '127.0.0.1', 'nightspire.gg', 'www.nightspire.gg'] SECURE_SSL_REDIRECT = False SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') SECURE_HSTS_SECONDS = 0 @@ -58,8 +58,8 @@ else: CSRF_TRUSTED_ORIGINS = [ - "https://www.novawow.com", - "https://novawow.com" + "https://www.nightspire.gg", + "https://nightspire.gg" ] # Application definition @@ -138,6 +138,7 @@ SECURE_CONTENT_TYPE_NOSNIFF = False MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', + 'whitenoise.middleware.WhiteNoiseMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.locale.LocaleMiddleware', 'django.middleware.common.CommonMiddleware', @@ -283,6 +284,13 @@ STATICFILES_DIRS = [ os.path.join(BASE_DIR, 'static'), ] +# WhiteNoise sirve los estáticos desde el propio proceso gunicorn (comprimidos), +# sin depender de que el reverse proxy tenga acceso de lectura a /root. +STORAGES = { + "default": {"BACKEND": "django.core.files.storage.FileSystemStorage"}, + "staticfiles": {"BACKEND": "whitenoise.storage.CompressedStaticFilesStorage"}, +} + # Default primary key field type # https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field diff --git a/requirements.txt b/requirements.txt index 609e1c9..78f8e90 100644 --- a/requirements.txt +++ b/requirements.txt @@ -16,3 +16,4 @@ urllib3==2.7.0 python-dotenv==1.2.2 gunicorn==26.0.0 nh3==0.3.6 +whitenoise