Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add access control headers
Michał Ociepka44e33248ae8f
diff --git a/saleor/graphql/file_upload/views.py b/saleor/graphql/file_upload/views.pyindex 065442a94f..15c8f44c86 100644--- a/saleor/graphql/file_upload/views.py+++ b/saleor/graphql/file_upload/views.py@@ -1,3 +1,4 @@+from django.conf import settingsfrom graphene_django.views import GraphQLViewimport jsonimport graphene@@ -8,6 +9,18 @@ import grapheneclass FileUploadGraphQLView(GraphQLView):+ 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 dabe034c49..4e2aeac9a6 100644--- a/saleor/settings.py+++ b/saleor/settings.py@@ -373,7 +373,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')