Despliegue en nightspire.gg: dominio real, estáticos y home resiliente

- settings: ALLOWED_HOSTS y CSRF_TRUSTED_ORIGINS a nightspire.gg /
  www.nightspire.gg (+ IP del servidor). Se retira el antiguo novawow.com.
- WhiteNoise para servir estáticos desde gunicorn (el reverse proxy Caddy
  corre como usuario 'caddy' y no puede leer /root): middleware +
  STORAGES con CompressedStaticFilesStorage. Añadido a requirements.txt.
- home: get_online_characters_count() ahora tolera que la BD de personajes
  (AzerothCore) no exista/esté vacía y devuelve 0 en vez de provocar un 500
  en la portada (mismo criterio que el context_processor get_server_info).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-07-12 20:01:43 +00:00
parent 96ab91a82b
commit 1ee126a69f
3 changed files with 23 additions and 8 deletions
+6
View File
@@ -2,10 +2,16 @@ from ._base import *
def get_online_characters_count():
# 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
+12 -4
View File
@@ -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
+1
View File
@@ -16,3 +16,4 @@ urllib3==2.7.0
python-dotenv==1.2.2
gunicorn==26.0.0
nh3==0.3.6
whitenoise