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:
+10
-4
@@ -2,10 +2,16 @@ from ._base import *
|
|||||||
|
|
||||||
|
|
||||||
def get_online_characters_count():
|
def get_online_characters_count():
|
||||||
with connections['acore_characters'].cursor() as cursor:
|
# Si la BD de personajes (AzerothCore) aún no está disponible/poblada,
|
||||||
cursor.execute("SELECT COUNT(*) FROM characters WHERE online = 1")
|
# no rompemos la portada: devolvemos 0 como hace el context_processor.
|
||||||
result = cursor.fetchone()
|
try:
|
||||||
return result[0] if result else 0
|
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):
|
def check_server_status(host, port):
|
||||||
if not host or host == "N/A":
|
if not host or host == "N/A":
|
||||||
return False
|
return False
|
||||||
|
|||||||
+12
-4
@@ -37,7 +37,7 @@ SECRET_KEY = os.getenv('DJANGO_SECRET_KEY', 'django-insecure-dev-key-change-me')
|
|||||||
DEBUG = _env_bool('DJANGO_DEBUG', False)
|
DEBUG = _env_bool('DJANGO_DEBUG', False)
|
||||||
|
|
||||||
if not DEBUG:
|
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_SSL_REDIRECT = False
|
||||||
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
|
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
|
||||||
SECURE_HSTS_SECONDS = 31536000 # Habilita HSTS por 1 año
|
SECURE_HSTS_SECONDS = 31536000 # Habilita HSTS por 1 año
|
||||||
@@ -47,7 +47,7 @@ if not DEBUG:
|
|||||||
CSRF_COOKIE_SECURE = True
|
CSRF_COOKIE_SECURE = True
|
||||||
else:
|
else:
|
||||||
# Modo desarrollo, no se aplican configuraciones de seguridad
|
# 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_SSL_REDIRECT = False
|
||||||
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
|
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
|
||||||
SECURE_HSTS_SECONDS = 0
|
SECURE_HSTS_SECONDS = 0
|
||||||
@@ -58,8 +58,8 @@ else:
|
|||||||
|
|
||||||
|
|
||||||
CSRF_TRUSTED_ORIGINS = [
|
CSRF_TRUSTED_ORIGINS = [
|
||||||
"https://www.novawow.com",
|
"https://www.nightspire.gg",
|
||||||
"https://novawow.com"
|
"https://nightspire.gg"
|
||||||
]
|
]
|
||||||
|
|
||||||
# Application definition
|
# Application definition
|
||||||
@@ -138,6 +138,7 @@ SECURE_CONTENT_TYPE_NOSNIFF = False
|
|||||||
|
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
'django.middleware.security.SecurityMiddleware',
|
'django.middleware.security.SecurityMiddleware',
|
||||||
|
'whitenoise.middleware.WhiteNoiseMiddleware',
|
||||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||||
'django.middleware.locale.LocaleMiddleware',
|
'django.middleware.locale.LocaleMiddleware',
|
||||||
'django.middleware.common.CommonMiddleware',
|
'django.middleware.common.CommonMiddleware',
|
||||||
@@ -283,6 +284,13 @@ STATICFILES_DIRS = [
|
|||||||
os.path.join(BASE_DIR, 'static'),
|
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
|
# Default primary key field type
|
||||||
# https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field
|
# https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field
|
||||||
|
|
||||||
|
|||||||
@@ -16,3 +16,4 @@ urllib3==2.7.0
|
|||||||
python-dotenv==1.2.2
|
python-dotenv==1.2.2
|
||||||
gunicorn==26.0.0
|
gunicorn==26.0.0
|
||||||
nh3==0.3.6
|
nh3==0.3.6
|
||||||
|
whitenoise
|
||||||
|
|||||||
Reference in New Issue
Block a user