From 7bc2758ee2e3927e56063af6b9be07e2c70cbb75 Mon Sep 17 00:00:00 2001 From: Francesco Grazioso Date: Mon, 29 Apr 2024 15:04:04 +0200 Subject: [PATCH] add cors --- api/api/settings.py | 15 +++++++++++++++ requirements.txt | 3 ++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/api/api/settings.py b/api/api/settings.py index b7dd350..a45b242 100644 --- a/api/api/settings.py +++ b/api/api/settings.py @@ -37,11 +37,13 @@ INSTALLED_APPS = [ "django.contrib.sessions", "django.contrib.messages", "django.contrib.staticfiles", + "corsheaders", "endpoints", "rest_framework", ] MIDDLEWARE = [ + "corsheaders.middleware.CorsMiddleware", "django.middleware.security.SecurityMiddleware", "django.contrib.sessions.middleware.SessionMiddleware", "django.middleware.common.CommonMiddleware", @@ -123,3 +125,16 @@ STATIC_URL = "static/" # https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" + +CORS_ALLOWED_ORIGINS = [ + "http://localhost:5173", +] + +CORS_ALLOW_METHODS = ( + "DELETE", + "GET", + "OPTIONS", + "PATCH", + "POST", + "PUT", +) diff --git a/requirements.txt b/requirements.txt index dbc42c4..d471fcb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,4 +7,5 @@ pycryptodome m3u8 lxml django==4.2.11 -djangorestframework==3.15.1 \ No newline at end of file +djangorestframework==3.15.1 +django-cors-headers==4.3.1 \ No newline at end of file