Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add access control headers
Michał Ociepkae0b1f50e09c0
diff --git a/saleor/graphql/file_upload/views.py b/saleor/graphql/file_upload/views.pyindex ee8fc339eb..4eb18d78f0 100644--- a/saleor/graphql/file_upload/views.py+++ b/saleor/graphql/file_upload/views.py@@ -1,6 +1,5 @@import json-import graphenefrom django.conf import settingsfrom graphene_django.views import GraphQLView@@ -23,6 +22,18 @@ class FileUploadGraphQLView(GraphQLView):'Access-Control-Allow-Headers'] = 'Origin, Content-Type, Accept, Authorization'return response+ def dispatch(self, request, *args, **kwargs):+ # Handle options method the GraphQlView restricts it.+ if request.method == 'OPTIONS':+ response = self.options(request, *args, **kwargs)+ else:+ response = super().dispatch(request, *args, **kwargs)+ # Add access control headers+ response['Access-Control-Allow-Origin'] = ','.join(settings.ALLOWED_HOSTS)+ response['Access-Control-Allow-Methods'] = 'POST, OPTIONS'+ response['Access-Control-Allow-Headers'] = 'Origin, Content-Type, Accept, Authorization'+ return response+@staticmethoddef get_graphql_params(request, data):content_type = GraphQLView.get_content_type(request)diff --git a/saleor/settings.py b/saleor/settings.pyindex 636f6a18a2..faf45c0c9d 100644--- a/saleor/settings.py+++ b/saleor/settings.py@@ -376,7 +376,7 @@ bootstrap4 = {TEST_RUNNER = ''ALLOWED_HOSTS = get_list(- os.environ.get('ALLOWED_HOSTS', 'localhost,127.0.0.1'))+ os.environ.get('ALLOWED_HOSTS', '*'))SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')