fix: allow all hosts to resolve kube-probe 400 error
Build & Push Docker Image (Backend) / build (push) Has been cancelled
Build & Push Docker Image (Backend) / build (push) Has been cancelled
This commit is contained in:
+209
-213
@@ -1,214 +1,210 @@
|
|||||||
"""
|
"""
|
||||||
Django settings for core project.
|
Django settings for core project.
|
||||||
|
|
||||||
Generated by 'django-admin startproject' using Django 6.0.2.
|
Generated by 'django-admin startproject' using Django 6.0.2.
|
||||||
|
|
||||||
For more information on this file, see
|
For more information on this file, see
|
||||||
https://docs.djangoproject.com/en/6.0/topics/settings/
|
https://docs.djangoproject.com/en/6.0/topics/settings/
|
||||||
|
|
||||||
For the full list of settings and their values, see
|
For the full list of settings and their values, see
|
||||||
https://docs.djangoproject.com/en/6.0/ref/settings/
|
https://docs.djangoproject.com/en/6.0/ref/settings/
|
||||||
"""
|
"""
|
||||||
import os
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from django.templatetags.static import static
|
from django.templatetags.static import static
|
||||||
|
|
||||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||||
|
|
||||||
|
|
||||||
# Quick-start development settings - unsuitable for production
|
# Quick-start development settings - unsuitable for production
|
||||||
# See https://docs.djangoproject.com/en/6.0/howto/deployment/checklist/
|
# See https://docs.djangoproject.com/en/6.0/howto/deployment/checklist/
|
||||||
|
|
||||||
# SECURITY WARNING: keep the secret key used in production secret!
|
# SECURITY WARNING: keep the secret key used in production secret!
|
||||||
SECRET_KEY = os.environ.get("SECRET_KEY", "unsafe-dev-secret")
|
SECRET_KEY = os.environ.get("SECRET_KEY", "unsafe-dev-secret")
|
||||||
|
|
||||||
# SECURITY WARNING: don't run with debug turned on in production!
|
# SECURITY WARNING: don't run with debug turned on in production!
|
||||||
DEBUG = False
|
DEBUG = False
|
||||||
|
|
||||||
# อนุญาตให้ Domain ใหม่เข้าถึง Application ได้
|
# อนุญาตให้ Domain ใหม่เข้าถึง Application ได้
|
||||||
ALLOWED_HOSTS = [
|
ALLOWED_HOSTS = ['*']
|
||||||
"lms-admin.panmodel.com",
|
|
||||||
"api.panmodel.com",
|
# Application definition
|
||||||
"127.0.0.1",
|
INSTALLED_APPS = [
|
||||||
]
|
"unfold", # ต้องอยู่บนสุด ก่อน django.contrib.admin
|
||||||
|
"unfold.contrib.filters", # Filter สวย ๆ
|
||||||
# Application definition
|
"unfold.contrib.forms", # ฟอร์มสวย ๆ
|
||||||
INSTALLED_APPS = [
|
"unfold.contrib.import_export", # ใช้คู่กับ import_export
|
||||||
"unfold", # ต้องอยู่บนสุด ก่อน django.contrib.admin
|
|
||||||
"unfold.contrib.filters", # Filter สวย ๆ
|
'django.contrib.admin',
|
||||||
"unfold.contrib.forms", # ฟอร์มสวย ๆ
|
'django.contrib.auth',
|
||||||
"unfold.contrib.import_export", # ใช้คู่กับ import_export
|
'django.contrib.contenttypes',
|
||||||
|
'django.contrib.sessions',
|
||||||
'django.contrib.admin',
|
'django.contrib.messages',
|
||||||
'django.contrib.auth',
|
'django.contrib.staticfiles',
|
||||||
'django.contrib.contenttypes',
|
|
||||||
'django.contrib.sessions',
|
# Third-party Apps
|
||||||
'django.contrib.messages',
|
'rest_framework', # สำหรับจัดการ API
|
||||||
'django.contrib.staticfiles',
|
'corsheaders', # สำหรับจัดการ CORS (สำคัญมากถ้ามีหน้าบ้านแยก)
|
||||||
|
|
||||||
# Third-party Apps
|
# LOCAL APPS
|
||||||
'rest_framework', # สำหรับจัดการ API
|
'apps.accounts',
|
||||||
'corsheaders', # สำหรับจัดการ CORS (สำคัญมากถ้ามีหน้าบ้านแยก)
|
'apps.content',
|
||||||
|
'apps.courses',
|
||||||
# LOCAL APPS
|
'apps.common',
|
||||||
'apps.accounts',
|
|
||||||
'apps.content',
|
]
|
||||||
'apps.courses',
|
|
||||||
'apps.common',
|
MIDDLEWARE = [
|
||||||
|
'corsheaders.middleware.CorsMiddleware', # สำคัญมากสำหรับ Frontend
|
||||||
]
|
'django.middleware.security.SecurityMiddleware',
|
||||||
|
'whitenoise.middleware.WhiteNoiseMiddleware',
|
||||||
MIDDLEWARE = [
|
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||||
'corsheaders.middleware.CorsMiddleware', # สำคัญมากสำหรับ Frontend
|
'django.middleware.common.CommonMiddleware',
|
||||||
'django.middleware.security.SecurityMiddleware',
|
'django.middleware.csrf.CsrfViewMiddleware',
|
||||||
'whitenoise.middleware.WhiteNoiseMiddleware',
|
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
'django.contrib.messages.middleware.MessageMiddleware',
|
||||||
'django.middleware.common.CommonMiddleware',
|
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||||
'django.middleware.csrf.CsrfViewMiddleware',
|
]
|
||||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
|
||||||
'django.contrib.messages.middleware.MessageMiddleware',
|
ROOT_URLCONF = 'core.urls'
|
||||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
|
||||||
]
|
TEMPLATES = [
|
||||||
|
{
|
||||||
ROOT_URLCONF = 'core.urls'
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||||
|
'DIRS': [],
|
||||||
TEMPLATES = [
|
'APP_DIRS': True,
|
||||||
{
|
'OPTIONS': {
|
||||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
'context_processors': [
|
||||||
'DIRS': [],
|
'django.template.context_processors.request',
|
||||||
'APP_DIRS': True,
|
'django.contrib.auth.context_processors.auth',
|
||||||
'OPTIONS': {
|
'django.contrib.messages.context_processors.messages',
|
||||||
'context_processors': [
|
],
|
||||||
'django.template.context_processors.request',
|
},
|
||||||
'django.contrib.auth.context_processors.auth',
|
},
|
||||||
'django.contrib.messages.context_processors.messages',
|
]
|
||||||
],
|
|
||||||
},
|
WSGI_APPLICATION = 'core.wsgi.application'
|
||||||
},
|
|
||||||
]
|
# Database
|
||||||
|
# https://docs.djangoproject.com/en/6.0/ref/settings/#databases
|
||||||
WSGI_APPLICATION = 'core.wsgi.application'
|
|
||||||
|
DATABASES = {
|
||||||
# Database
|
'default': {
|
||||||
# https://docs.djangoproject.com/en/6.0/ref/settings/#databases
|
'ENGINE': 'django.db.backends.postgresql', # เปลี่ยนจาก django_cockroachdb
|
||||||
|
'NAME': os.environ.get('DB_NAME', 'lms'),
|
||||||
DATABASES = {
|
'HOST': os.environ.get('DB_HOST', 'localhost'),
|
||||||
'default': {
|
'PORT': os.environ.get('DB_PORT', '5432'), # พอร์ตมาตรฐาน PostgreSQL
|
||||||
'ENGINE': 'django.db.backends.postgresql', # เปลี่ยนจาก django_cockroachdb
|
'USER': os.environ.get('DB_USER', 'lms'),
|
||||||
'NAME': os.environ.get('DB_NAME', 'lms'),
|
'PASSWORD': os.environ.get('DB_PASSWORD', 'lms123'),
|
||||||
'HOST': os.environ.get('DB_HOST', 'localhost'),
|
'OPTIONS': {
|
||||||
'PORT': os.environ.get('DB_PORT', '5432'), # พอร์ตมาตรฐาน PostgreSQL
|
'connect_timeout': 5,
|
||||||
'USER': os.environ.get('DB_USER', 'lms'),
|
},
|
||||||
'PASSWORD': os.environ.get('DB_PASSWORD', 'lms123'),
|
'ATOMIC_REQUESTS': True, # PostgreSQL รองรับ Atomic Requests ได้อย่างมีประสิทธิภาพ
|
||||||
'OPTIONS': {
|
},
|
||||||
'connect_timeout': 5,
|
|
||||||
},
|
}
|
||||||
'ATOMIC_REQUESTS': True, # PostgreSQL รองรับ Atomic Requests ได้อย่างมีประสิทธิภาพ
|
|
||||||
},
|
REST_FRAMEWORK = {
|
||||||
|
"DEFAULT_AUTHENTICATION_CLASSES": (
|
||||||
}
|
"rest_framework.authentication.SessionAuthentication",
|
||||||
|
"rest_framework.authentication.TokenAuthentication",
|
||||||
REST_FRAMEWORK = {
|
),
|
||||||
"DEFAULT_AUTHENTICATION_CLASSES": (
|
}
|
||||||
"rest_framework.authentication.SessionAuthentication",
|
|
||||||
"rest_framework.authentication.TokenAuthentication",
|
CORS_ALLOW_ALL_ORIGINS = True # ควรเป็น False ใน Production
|
||||||
),
|
|
||||||
}
|
# ยืนยันความปลอดภัยให้ Domain ใหม่ (ต้องใส่ https:// ด้วยครับ)
|
||||||
|
CSRF_TRUSTED_ORIGINS = [
|
||||||
CORS_ALLOW_ALL_ORIGINS = True # ควรเป็น False ใน Production
|
"https://lms-admin.panmodel.com",
|
||||||
|
]
|
||||||
# ยืนยันความปลอดภัยให้ Domain ใหม่ (ต้องใส่ https:// ด้วยครับ)
|
|
||||||
CSRF_TRUSTED_ORIGINS = [
|
# บอกให้ Django รู้ว่าอยู่หลัง Nginx Ingress (เพื่อให้ดึง Protocol/Host ถูกต้อง)
|
||||||
"https://lms-admin.panmodel.com",
|
USE_X_FORWARDED_HOST = True
|
||||||
]
|
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
|
||||||
|
|
||||||
# บอกให้ Django รู้ว่าอยู่หลัง Nginx Ingress (เพื่อให้ดึง Protocol/Host ถูกต้อง)
|
|
||||||
USE_X_FORWARDED_HOST = True
|
# Password validation
|
||||||
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
|
# https://docs.djangoproject.com/en/6.0/ref/settings/#auth-password-validators
|
||||||
|
|
||||||
|
AUTH_PASSWORD_VALIDATORS = [
|
||||||
# Password validation
|
{
|
||||||
# https://docs.djangoproject.com/en/6.0/ref/settings/#auth-password-validators
|
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
||||||
|
},
|
||||||
AUTH_PASSWORD_VALIDATORS = [
|
{
|
||||||
{
|
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
|
||||||
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
},
|
||||||
},
|
{
|
||||||
{
|
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
|
||||||
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
|
},
|
||||||
},
|
{
|
||||||
{
|
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
|
||||||
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
|
},
|
||||||
},
|
]
|
||||||
{
|
|
||||||
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
|
|
||||||
},
|
# Internationalization
|
||||||
]
|
# https://docs.djangoproject.com/en/6.0/topics/i18n/
|
||||||
|
|
||||||
|
# เปลี่ยนเป็นภาษาไทยสำหรับหน้า Admin
|
||||||
# Internationalization
|
LANGUAGE_CODE = 'th'
|
||||||
# https://docs.djangoproject.com/en/6.0/topics/i18n/
|
# ตั้งเป็นเวลาประเทศไทย
|
||||||
|
TIME_ZONE = 'Asia/Bangkok'
|
||||||
# เปลี่ยนเป็นภาษาไทยสำหรับหน้า Admin
|
|
||||||
LANGUAGE_CODE = 'th'
|
USE_I18N = True
|
||||||
# ตั้งเป็นเวลาประเทศไทย
|
|
||||||
TIME_ZONE = 'Asia/Bangkok'
|
USE_TZ = True
|
||||||
|
|
||||||
USE_I18N = True
|
# Static files (CSS, JavaScript, Images)
|
||||||
|
# https://docs.djangoproject.com/en/6.0/howto/static-files/
|
||||||
USE_TZ = True
|
|
||||||
|
STATIC_URL = '/static/'
|
||||||
# Static files (CSS, JavaScript, Images)
|
|
||||||
# https://docs.djangoproject.com/en/6.0/howto/static-files/
|
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
|
||||||
|
|
||||||
STATIC_URL = '/static/'
|
STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"
|
||||||
|
|
||||||
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
|
STATICFILES_DIRS = [
|
||||||
|
os.path.join(BASE_DIR, 'static'),
|
||||||
STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"
|
]
|
||||||
|
|
||||||
STATICFILES_DIRS = [
|
AUTH_USER_MODEL = "accounts.CustomUser"
|
||||||
os.path.join(BASE_DIR, 'static'),
|
|
||||||
]
|
# ตั้งค่าเมนูและ Dashboard (UNFOLD Configuration)
|
||||||
|
UNFOLD = {
|
||||||
AUTH_USER_MODEL = "accounts.CustomUser"
|
"SITE_TITLE": "LMS เพื่อสาธารณะ",
|
||||||
|
"SITE_HEADER": "ระบบคลังความรู้เพื่อเยาวชนไทย",
|
||||||
# ตั้งค่าเมนูและ Dashboard (UNFOLD Configuration)
|
"SITE_SYMBOL": "menu_book",
|
||||||
UNFOLD = {
|
"SHOW_HISTORY": True,
|
||||||
"SITE_TITLE": "LMS เพื่อสาธารณะ",
|
"STYLES": [
|
||||||
"SITE_HEADER": "ระบบคลังความรู้เพื่อเยาวชนไทย",
|
lambda request: static("css/unfold_th_font.css"),
|
||||||
"SITE_SYMBOL": "menu_book",
|
],
|
||||||
"SHOW_HISTORY": True,
|
"SCRIPTS": [
|
||||||
"STYLES": [
|
lambda request: static("unfold/js/admin.js"),
|
||||||
lambda request: static("css/unfold_th_font.css"),
|
],
|
||||||
],
|
|
||||||
"SCRIPTS": [
|
|
||||||
lambda request: static("unfold/js/admin.js"),
|
"COLORS": {
|
||||||
],
|
"primary": {
|
||||||
|
"50": "#e0f2fe", # ฟ้าอ่อนมาก (ใช้กับพื้นหลังอ่อน)
|
||||||
|
"100": "#bae6fd",
|
||||||
"COLORS": {
|
"200": "#7dd3fc",
|
||||||
"primary": {
|
"300": "#38bdf8",
|
||||||
"50": "#e0f2fe", # ฟ้าอ่อนมาก (ใช้กับพื้นหลังอ่อน)
|
"400": "#0ea5e9",
|
||||||
"100": "#bae6fd",
|
"500": "#0284c7", # สีหลัก
|
||||||
"200": "#7dd3fc",
|
"600": "#0369a1",
|
||||||
"300": "#38bdf8",
|
"700": "#075985",
|
||||||
"400": "#0ea5e9",
|
"800": "#0c4a6e",
|
||||||
"500": "#0284c7", # สีหลัก
|
"900": "#082f49",
|
||||||
"600": "#0369a1",
|
"950": "#020617",
|
||||||
"700": "#075985",
|
},
|
||||||
"800": "#0c4a6e",
|
# ถ้าอยากปรับโทนสีเทา/พื้นหลัง (Base) ให้เข้มขรึมขึ้น
|
||||||
"900": "#082f49",
|
"base": {
|
||||||
"950": "#020617",
|
"50": "#f8fafc",
|
||||||
},
|
"900": "#0f172a", # สีพื้นหลัง Dark Mode
|
||||||
# ถ้าอยากปรับโทนสีเทา/พื้นหลัง (Base) ให้เข้มขรึมขึ้น
|
"950": "#020617",
|
||||||
"base": {
|
},
|
||||||
"50": "#f8fafc",
|
},
|
||||||
"900": "#0f172a", # สีพื้นหลัง Dark Mode
|
|
||||||
"950": "#020617",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user