import os,sys from datetime import timedelta import django from django.utils.encoding import force_str django.utils.encoding.force_text = force_str # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) PROJECT_ROOT = os.path.dirname(__file__) sys.path.insert(0,os.path.join(PROJECT_ROOT,'apps')) AUTH_USER_MODEL = 'authAPI.CustomUser' try: if os.environ['debug'] == 'False': DEBUG = False else: DEBUG = True except: DEBUG = True CORS_ORIGIN_ALLOW_ALL = True if DEBUG: SECRET_KEY = 'django-insecure-e*vqkvk_c%y&(v-^isb_%uwxq#y4eun3xhf4al_5f_)&14e5f0' else: try: SECRET_KEY = os.environ["SECRET_KEY"] except KeyError as e: raise RuntimeError("Could not find a SECRET_KEY in environment") from e from .prod import * ALLOWED_HOSTS=["*"] # Application definition CORS_ALLOWED_ORIGINS = [ "http://188.72.209.29", "http://188.72.209.29:80", "http://188.72.209.29:8000", "http://localhost:8000", "http://127.0.0.1:3000", ] CORS_ALLOW_METHODS = [ "GET", "POST", "PUT", "OPTIONS" ] INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'rest_framework', 'graphene_django', 'corsheaders', 'goods.apps.GoodsConfig', 'authAPI.apps.AuthAPIConfig', 'orders.apps.OrdersConfig', 'categories.apps.CategoriesConfig', ] 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', ] AUTHENTICATION_BACKENDS = [ "graphql_jwt.backends.JSONWebTokenBackend", "django.contrib.auth.backends.ModelBackend", ] ROOT_URLCONF = 'store_back.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 = 'store_back.wsgi.application' AUTH_PASSWORD_VALIDATORS = [ { 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', }, { 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', }, { 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', }, { 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', }, ] # Internationalization # https://docs.djangoproject.com/en/4.0/topics/i18n/ LANGUAGE_CODE = 'en-us' TIME_ZONE = 'UTC' USE_I18N = True USE_TZ = True DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'dfi11snf6cpamj', 'USER' : 'qvkowaptdjfexz', 'PASSWORD' : '3ef6f3a16c918da406cd2b388042a45080ff7f9dd10d5f9cc1df0ec0eca8ab7a', 'HOST' : 'ec2-52-48-159-67.eu-west-1.compute.amazonaws.com', 'PORT' : '5432', } } # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/4.0/howto/static-files/ STATIC_ROOT = os.path.join(BASE_DIR, 'static') STATIC_URL = '/static/' MEDIA_ROOT = os.path.join(BASE_DIR, 'media').replace('\\', '/') MEDIA_URL = '/media/' # Default primary key field type # https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' GRAPHENE = { 'SCHEMA': 'store_back.schema', "MIDDLEWARE": [ "graphql_jwt.middleware.JSONWebTokenMiddleware", ], } GRAPHQL_JWT = { 'JWT_PAYLOAD_HANDLER': 'store_back.utils.jwt_payload', 'JWT_AUTH_HEADER_PREFIX': 'Bearer', 'JWT_VERIFY_EXPIRATION': True, 'JWT_LONG_RUNNING_REFRESH_TOKEN': True, 'JWT_EXPIRATION_DELTA': timedelta(days=30), 'JWT_REFRESH_EXPIRATION_DELTA':timedelta(days=1), 'JWT_SECRET_KEY': SECRET_KEY, 'JWT_ALGORITHM': 'HS256', } SIMPLE_JWT = { 'ACCESS_TOKEN_LIFETIME': timedelta(days=30), 'REFRESH_TOKEN_LIFETIME': timedelta(days=1), 'ROTATE_REFRESH_TOKENS': False, 'BLACKLIST_AFTER_ROTATION': False, 'UPDATE_LAST_LOGIN': False, 'ALGORITHM': 'HS256', 'SIGNING_KEY': SECRET_KEY, 'VERIFYING_KEY': None, 'AUDIENCE': None, 'ISSUER': None, 'JWK_URL': None, 'LEEWAY': 0, 'AUTH_HEADER_TYPES': ('Bearer',), 'AUTH_HEADER_NAME': 'HTTP_AUTHORIZATION', 'USER_ID_FIELD': '_id', 'USER_ID_CLAIM': 'user_id', 'USER_AUTHENTICATION_RULE': 'rest_framework_simplejwt.authentication.default_user_authentication_rule', 'AUTH_TOKEN_CLASSES': ('rest_framework_simplejwt.tokens.AccessToken',), 'TOKEN_TYPE_CLAIM': 'token_type', 'TOKEN_USER_CLASS': 'rest_framework_simplejwt.models.TokenUser', 'JTI_CLAIM': 'jti', 'SLIDING_TOKEN_REFRESH_EXP_CLAIM': 'refresh_exp', 'SLIDING_TOKEN_LIFETIME': timedelta(minutes=5), 'SLIDING_TOKEN_REFRESH_LIFETIME': timedelta(days=1), } REST_FRAMEWORK = { 'DEFAULT_AUTHENTICATION_CLASSES': ( 'rest_framework_simplejwt.authentication.JWTAuthentication', ) }