From 744c4a3deaf94ab6d3548cc05625827fa7be2a89 Mon Sep 17 00:00:00 2001 From: Jennings Zhang Date: Mon, 25 Nov 2024 09:15:07 -0500 Subject: [PATCH] Allow any CORS on api/v1/plugins/ and api/v1/plugins/metas/ --- chris_backend/plugins/apps.py | 4 ++++ chris_backend/plugins/handlers.py | 12 ++++++++++++ 2 files changed, 16 insertions(+) create mode 100755 chris_backend/plugins/handlers.py diff --git a/chris_backend/plugins/apps.py b/chris_backend/plugins/apps.py index 3b8de090..20a4fad1 100755 --- a/chris_backend/plugins/apps.py +++ b/chris_backend/plugins/apps.py @@ -3,3 +3,7 @@ class PluginsConfig(AppConfig): name = 'plugins' + + def ready(self): + from plugins import handlers + diff --git a/chris_backend/plugins/handlers.py b/chris_backend/plugins/handlers.py new file mode 100755 index 00000000..c5e14018 --- /dev/null +++ b/chris_backend/plugins/handlers.py @@ -0,0 +1,12 @@ +from corsheaders.signals import check_request_enabled +import re + +_ALLOWED = re.compile(r'/api/v1/plugins/(metas/)?(search/)?(\d+/)?') + + +def cors_allow_api_to_everyone(sender, request, **kwargs): + return _ALLOWED.fullmatch(request.path) + + +check_request_enabled.connect(cors_allow_api_to_everyone) +