revert: restaurar nombre api_config (revertir renombrado erróneo)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
3
app/api_config/.env.example
Normal file
3
app/api_config/.env.example
Normal file
@@ -0,0 +1,3 @@
|
||||
# core/.env
|
||||
APP_CUSTOM_SETTING="Este es un valor privado de la app"
|
||||
EXTERNAL_SERVICE_API_KEY="sk_test_12345"
|
||||
0
app/api_config/__init__.py
Normal file
0
app/api_config/__init__.py
Normal file
4
app/api_config/asgi.py
Normal file
4
app/api_config/asgi.py
Normal file
@@ -0,0 +1,4 @@
|
||||
import os
|
||||
from django.core.asgi import get_asgi_application
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'api_hub_dispatcher.settings')
|
||||
application = get_asgi_application()
|
||||
185
app/api_config/settings.py
Normal file
185
app/api_config/settings.py
Normal file
@@ -0,0 +1,185 @@
|
||||
from pathlib import Path
|
||||
import os
|
||||
from dotenv import load_dotenv
|
||||
from datetime import timedelta
|
||||
|
||||
SIMPLE_JWT = {
|
||||
# Cambiamos el tiempo de acceso a 3 horas
|
||||
'ACCESS_TOKEN_LIFETIME': timedelta(hours=3),
|
||||
|
||||
# El tiempo del refresh token suele ser mayor (por ejemplo, 1 día)
|
||||
'REFRESH_TOKEN_LIFETIME': timedelta(days=1),
|
||||
|
||||
# Otras configuraciones que ya tengas...
|
||||
'ALGORITHM': 'HS256',
|
||||
'AUTH_HEADER_TYPES': ('Bearer',),
|
||||
}
|
||||
|
||||
# 1. RUTA DEL SETTINGS Y CARGA DEL .ENV
|
||||
# Obtenemos la ruta de la carpeta donde está este archivo (core/)
|
||||
CURRENT_DIR = Path(__file__).resolve().parent
|
||||
BASE_DIR = CURRENT_DIR.parent
|
||||
|
||||
# Cargamos el .env específico de esta carpeta (core/.env)
|
||||
load_dotenv(dotenv_path=CURRENT_DIR / '.env')
|
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
SECRET_KEY = os.getenv('SECRET_KEY', 'django-insecure-default-key-change-it')
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
# Mejoramos el parseo de DEBUG para que no falle si viene como string
|
||||
DEBUG = os.getenv('DEBUG', 'True').lower() in ('true', '1', 't')
|
||||
|
||||
# 2. ALLOWED HOSTS
|
||||
# Limpiamos y centralizamos los hosts permitidos
|
||||
ALLOWED_HOSTS = [
|
||||
'v-encore-lab.com',
|
||||
'dev.v-encore-lab.com',
|
||||
'185.187.169.109',
|
||||
'localhost',
|
||||
'127.0.0.1',
|
||||
os.getenv('APP_CONTAINER_NAME', 'django_app_dev'), # Dinámico para Docker
|
||||
]
|
||||
|
||||
# Application definition
|
||||
INSTALLED_APPS = [
|
||||
'django.contrib.admin',
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
|
||||
# Plugins
|
||||
'rest_framework',
|
||||
'rest_framework.authtoken',
|
||||
'corsheaders',
|
||||
|
||||
# Tus Apps (Asegúrate de que el path sea correcto)
|
||||
'general',
|
||||
'promociones',
|
||||
'automatizados',
|
||||
'backend_admin',
|
||||
'common',
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
'corsheaders.middleware.CorsMiddleware',
|
||||
'django.middleware.security.SecurityMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.middleware.csrf.CsrfViewMiddleware',
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||
]
|
||||
|
||||
ROOT_URLCONF = 'api_hub_dispatcher.urls'
|
||||
|
||||
TEMPLATES = [
|
||||
{
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'DIRS': [],
|
||||
'APP_DIRS': True,
|
||||
'OPTIONS': {
|
||||
'context_processors': [
|
||||
'django.template.context_processors.debug',
|
||||
'django.template.context_processors.request',
|
||||
'django.contrib.auth.context_processors.auth',
|
||||
'django.contrib.messages.context_processors.messages',
|
||||
],
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
WSGI_APPLICATION = 'api_hub_dispatcher.wsgi.application'
|
||||
|
||||
# 3. DATABASE
|
||||
# En producción (cuando DB_HOST está definido) usa PostgreSQL.
|
||||
# En local/desarrollo sin configuración, cae a SQLite en data/
|
||||
if os.getenv('DB_HOST'):
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.postgresql',
|
||||
'NAME': os.getenv('DB_NAME', 'postgres'),
|
||||
'USER': os.getenv('DB_USER', 'postgres'),
|
||||
'PASSWORD': os.getenv('DB_PASSWORD', ''),
|
||||
'HOST': os.getenv('DB_HOST'),
|
||||
'PORT': os.getenv('DB_PORT', '5432'),
|
||||
}
|
||||
}
|
||||
else:
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': BASE_DIR / 'data' / 'db.sqlite3',
|
||||
}
|
||||
}
|
||||
|
||||
# Internationalization
|
||||
LANGUAGE_CODE = 'es-es'
|
||||
TIME_ZONE = 'Europe/Madrid'
|
||||
USE_I18N = True
|
||||
USE_TZ = True
|
||||
|
||||
# Static files
|
||||
STATIC_URL = '/static/'
|
||||
STATIC_ROOT = BASE_DIR / 'staticfiles'
|
||||
|
||||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
||||
|
||||
# REST Framework
|
||||
REST_FRAMEWORK = {
|
||||
'DEFAULT_AUTHENTICATION_CLASSES': (
|
||||
'rest_framework_simplejwt.authentication.JWTAuthentication',
|
||||
),
|
||||
'DEFAULT_PERMISSION_CLASSES': (
|
||||
'rest_framework.permissions.IsAuthenticated',
|
||||
),
|
||||
}
|
||||
|
||||
SIMPLE_JWT = {
|
||||
"ACCESS_TOKEN_LIFETIME": timedelta(hours=1),
|
||||
"REFRESH_TOKEN_LIFETIME": timedelta(days=1),
|
||||
}
|
||||
|
||||
# CORS & CSRF
|
||||
CORS_ALLOW_ALL_ORIGINS = DEBUG # Solo permitir todo en modo DEBUG
|
||||
CSRF_TRUSTED_ORIGINS = [
|
||||
'https://v-encore-lab.com',
|
||||
'http://localhost:8000',
|
||||
'http://127.0.0.1:8000',
|
||||
]
|
||||
|
||||
# Logging simplificado
|
||||
LOGGING = {
|
||||
'version': 1,
|
||||
'disable_existing_loggers': False,
|
||||
'formatters': {
|
||||
'verbose': {
|
||||
'format': '{levelname} {asctime} {module} {message}',
|
||||
'style': '{',
|
||||
},
|
||||
},
|
||||
'handlers': {
|
||||
'console': {
|
||||
'class': 'logging.StreamHandler',
|
||||
'formatter': 'verbose',
|
||||
},
|
||||
},
|
||||
'loggers': {
|
||||
'': {
|
||||
'handlers': ['console'],
|
||||
'level': os.getenv('LOG_LEVEL', 'INFO'),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
# --- CONFIGURACIONES PERSONALIZADAS DE LA APP ---
|
||||
|
||||
# Leemos la variable del .env (cargado previamente con load_dotenv)
|
||||
# Ponemos un valor por defecto por si se nos olvida ponerlo en el .env
|
||||
APP_CUSTOM_SETTING = os.getenv('APP_CUSTOM_SETTING', 'valor_por_defecto_seguro')
|
||||
|
||||
# Ejemplo de otra variable de API
|
||||
EXTERNAL_SERVICE_API_KEY = os.getenv('EXTERNAL_SERVICE_API_KEY', None)
|
||||
10
app/api_config/urls.py
Normal file
10
app/api_config/urls.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from django.urls import path, include
|
||||
from backend_admin import views as admin_views
|
||||
|
||||
urlpatterns = [
|
||||
path('admin/', include('backend_admin.urls')),
|
||||
path('api/general/', include('general.urls')),
|
||||
path('api/promociones/', include('promociones.urls')),
|
||||
path('api/automatizados/', include('automatizados.urls')),
|
||||
path('api/token/', admin_views.api_token, name='token_obtain_pair'),
|
||||
]
|
||||
7
app/api_config/wsgi.py
Normal file
7
app/api_config/wsgi.py
Normal file
@@ -0,0 +1,7 @@
|
||||
import os
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
|
||||
# Este es el enlace con tus configuraciones
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'api_hub_dispatcher.settings')
|
||||
|
||||
application = get_wsgi_application()
|
||||
Reference in New Issue
Block a user