diff --git a/build_files.sh b/build_files.sh new file mode 100644 index 0000000..62e7769 --- /dev/null +++ b/build_files.sh @@ -0,0 +1,4 @@ +# build_files.sh + +pip install -r requirements.txt +python3.9 manage.py collectstatic --noinput diff --git a/main/settings.py b/main/settings.py index d187f11..bab1af4 100644 --- a/main/settings.py +++ b/main/settings.py @@ -2,10 +2,13 @@ import os import django_heroku from django.conf import settings +from dotenv import load_dotenv # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent +# load environment variables +load_dotenv() # Quick-start development settings - unsuitable for production @@ -16,7 +19,7 @@ # SECURITY WARNING: don't run with debug turned on in production! DEBUG = False -ALLOWED_HOSTS = ['*'] +ALLOWED_HOSTS = ["127.0.0.1", ".vercel.app", ".now.sh"] # Application definition @@ -131,12 +134,12 @@ DATABASES = { 'default': { - 'ENGINE': 'django.db.backends.mysql', - 'NAME': 'django-server', - 'USER': 'dbuser', - 'PASSWORD': 'Rabbani@123', - 'HOST': 'django-server.mysql.database.azure.com', - 'PORT': '3306', + 'ENGINE': os.getenv("DB_ENGINE"), + 'NAME': os.getenv("DB_NAME"), + 'USER': os.getenv("DB_USER"), + 'PASSWORD': os.getenv("DB_PASSWORD"), + 'HOST': os.getenv("DB_HOST"), + 'PORT': os.getenv("DB_PORT"), } } diff --git a/main/urls.py b/main/urls.py index 0f44a8f..6abf599 100644 --- a/main/urls.py +++ b/main/urls.py @@ -41,3 +41,6 @@ urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) + +if settings.DEBUG: + urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) \ No newline at end of file diff --git a/main/wsgi.py b/main/wsgi.py index e1c99c8..d49d6f4 100644 --- a/main/wsgi.py +++ b/main/wsgi.py @@ -14,3 +14,5 @@ os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'main.settings') application = get_wsgi_application() + +app = application \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 44b7364..e2a3899 100644 --- a/requirements.txt +++ b/requirements.txt @@ -41,6 +41,7 @@ py pycodestyle pyparsing pytest +python-dotenv python-slugify pytz redis diff --git a/versel.json b/versel.json new file mode 100644 index 0000000..eaded20 --- /dev/null +++ b/versel.json @@ -0,0 +1,29 @@ +# versel.json + +{ + "version": 2, + "builds": [ + { + "src": "main/wsgi.py", + "use": "@vercel/python", + "config": { "maxLambdaSize": "15mb", "runtime": "python3.9" } + }, + { + "src": "build_files.sh", + "use": "@vercel/static-build", + "config": { + "distDir": "staticfiles" + } + } + ], + "routes": [ + { + "src": "/static/(.*)", + "dest": "/static/$1" + }, + { + "src": "/(.*)", + "dest": "main/wsgi.py" + } + ] +}