From 0bdb466ffd4514cbbf717b33d3d1b8b986d9f28d Mon Sep 17 00:00:00 2001 From: zakhy Date: Fri, 20 Sep 2024 11:15:20 +0700 Subject: [PATCH] add cors --- app/poetry.lock | 17 ++++++++++++++++- app/project/settings.py | 7 +++++++ app/pyproject.toml | 1 + app/requirements.txt | Bin 304 -> 360 bytes 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/app/poetry.lock b/app/poetry.lock index 63dc26d..aceb2a3 100644 --- a/app/poetry.lock +++ b/app/poetry.lock @@ -37,6 +37,21 @@ tzdata = {version = "*", markers = "sys_platform == \"win32\""} argon2 = ["argon2-cffi (>=19.1.0)"] bcrypt = ["bcrypt"] +[[package]] +name = "django-cors-headers" +version = "4.4.0" +description = "django-cors-headers is a Django application for handling the server headers required for Cross-Origin Resource Sharing (CORS)." +optional = false +python-versions = ">=3.8" +files = [ + {file = "django_cors_headers-4.4.0-py3-none-any.whl", hash = "sha256:5c6e3b7fe870876a1efdfeb4f433782c3524078fa0dc9e0195f6706ce7a242f6"}, + {file = "django_cors_headers-4.4.0.tar.gz", hash = "sha256:92cf4633e22af67a230a1456cb1b7a02bb213d6536d2dcb2a4a24092ea9cebc2"}, +] + +[package.dependencies] +asgiref = ">=3.6" +django = ">=3.2" + [[package]] name = "gunicorn" version = "23.0.0" @@ -190,4 +205,4 @@ files = [ [metadata] lock-version = "2.0" python-versions = "^3.10" -content-hash = "0fd97d09e063483e162b9041c2e718f1e9a93161d2bb3eda6800f46052566123" +content-hash = "6e12b80930992cd89d60882a682a72b9be3e6f4dcd614695c5e769bdc8f4a6c8" diff --git a/app/project/settings.py b/app/project/settings.py index c79c0a4..2b255a2 100644 --- a/app/project/settings.py +++ b/app/project/settings.py @@ -16,12 +16,14 @@ INSTALLED_APPS = [ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', + 'corsheaders', 'users', ] MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', + 'corsheaders.middleware.CorsMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', @@ -87,3 +89,8 @@ STATIC_URL = 'static/' STATIC_ROOT = os.path.join(BASE_DIR, 'static') DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' + +CORS_ALLOWED_ORIGINS = [ + 'http://localhost:443', + 'http://localhost:80', +] diff --git a/app/pyproject.toml b/app/pyproject.toml index 0c3338e..223b1be 100644 --- a/app/pyproject.toml +++ b/app/pyproject.toml @@ -10,6 +10,7 @@ python = "^3.10" django = "^4.2" gunicorn = "^23.0.0" psycopg2-binary = "^2.9.9" +django-cors-headers = "^4.4.0" [build-system] diff --git a/app/requirements.txt b/app/requirements.txt index 3b1d6be6a9314c68a4d662dc60312ac10f0256ba..d2d0bb91479e44465e0955568ede51029836d255 100644 GIT binary patch delta 61 zcmdnM^nz)ElW__|7DFOK9z!}qK7%epGLS4{C