implement cors for browser extension

This commit is contained in:
simon 2022-01-14 14:46:00 +07:00
parent c703105c5e
commit 3df8f65db6
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
3 changed files with 13 additions and 0 deletions

View File

@ -178,6 +178,7 @@ class DownloadApiListView(ApiBaseView):
@staticmethod
def post(request):
"""add list of videos to download queue"""
print(f"request meta data: {request.META}")
data = request.data
try:
to_add = data["data"]

View File

@ -14,6 +14,7 @@ import hashlib
from os import environ, path
from pathlib import Path
from corsheaders.defaults import default_headers
from home.src.config import AppConfig
# Build paths inside the project like this: BASE_DIR / 'subdir'.
@ -41,6 +42,7 @@ INSTALLED_APPS = [
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"corsheaders",
"whitenoise.runserver_nostatic",
"django.contrib.staticfiles",
"django.contrib.humanize",
@ -52,6 +54,7 @@ INSTALLED_APPS = [
MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"corsheaders.middleware.CorsMiddleware",
"whitenoise.middleware.WhiteNoiseMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
@ -140,3 +143,11 @@ DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
LOGIN_URL = "/login/"
LOGOUT_REDIRECT_URL = "/login/"
# Cors needed for browser extension
# background.js makes the request so HTTP_ORIGIN will be from extension
CORS_ALLOWED_ORIGIN_REGEXES = [r"moz-extension://*"]
CORS_ALLOW_HEADERS = list(default_headers) + [
"mode",
]

View File

@ -1,5 +1,6 @@
beautifulsoup4==4.10.0
celery==5.2.3
django-cors-headers==3.11.0
Django==4.0.1
djangorestframework==3.13.1
Pillow==9.0.0