diff --git a/BookingService/settings.py b/BookingService/settings.py index c5e6b08..9bcbb0d 100644 --- a/BookingService/settings.py +++ b/BookingService/settings.py @@ -12,6 +12,9 @@ https://docs.djangoproject.com/en/2.1/ref/settings/ import os +# Tell which environment +ENV = os.environ.get('ENV') + # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) @@ -22,9 +25,9 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) SECRET_KEY = 'l%o*o21h_a5^f+3xblzzfch*&2k_4pcak(o#t2@vymeb_mcy3$' # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True +DEBUG = ENV == 'DEV' -ALLOWED_HOSTS = [] +ALLOWED_HOSTS = [] if DEBUG else ['127.0.0.1', 'localhost', 'code.wh.sdu.edu.cn'] # Application definition @@ -82,6 +85,15 @@ DATABASES = { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), } +} if DEBUG else { + 'default': { + 'ENGINE': 'django.db.backends.postgresql', + 'NAME': 'bookingservice', + 'USER': 'postgres', + 'PASSWORD': 'sduwhsduwh', + 'HOST': '172.17.0.1', + 'PORT': '5432', + } } # Password validation @@ -155,6 +167,14 @@ SESSION_COOKIE_HTTPONLY = False APPEND_SLASH = True # CELERY -CELERY_BROKER_URL = 'amqp://guest:guest@davidz.cn' +CELERY_BROKER_URL = 'amqp://guest:guest@davidz.cn' if DEBUG else 'amqp://guest:guest@172.17.0.1' CELERY_TIMEZONE = 'Asia/Shanghai' + +if not DEBUG: + SECURE_SSL_REDIRECT = True + + # lower version of chrome and edge do not support same-site flag + SESSION_COOKIE_SAMESITE = None + + CSRF_COOKIE_SAMESITE = None diff --git a/BookingService/settings_production.py b/BookingService/settings_production.py deleted file mode 100644 index 6dc13bd..0000000 --- a/BookingService/settings_production.py +++ /dev/null @@ -1,23 +0,0 @@ -from .settings import * - -DEBUG = False - -ALLOWED_HOSTS = ['127.0.0.1', 'localhost', 'code.wh.sdu.edu.cn'] - -SECURE_SSL_REDIRECT = True - -# lower version of chrome and edge do not support same-site flag -SESSION_COOKIE_SAMESITE = None - -CSRF_COOKIE_SAMESITE = None - -DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.postgresql', - 'NAME': 'bookingservice', - 'USER': 'postgres', - 'PASSWORD': 'sduwhsduwh', - 'HOST': '172.17.0.1', - 'PORT': '5432', - } -} diff --git a/BookingService/wsgi.py b/BookingService/wsgi.py index a3ce3d9..2c3bc68 100644 --- a/BookingService/wsgi.py +++ b/BookingService/wsgi.py @@ -11,6 +11,6 @@ import os from django.core.wsgi import get_wsgi_application -os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'BookingService.settings_production') +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'BookingService.settings') application = get_wsgi_application()