Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Add access control headers

Michał Ociepka44e33248ae8f
diff --git a/saleor/graphql/file_upload/views.py b/saleor/graphql/file_upload/views.py
index 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 settings
from graphene_django.views import GraphQLView
import json
import graphene
@@ -8,6 +9,18 @@ import graphene
class 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
+
@staticmethod
def get_graphql_params(request, data):
content_type = GraphQLView.get_content_type(request)
diff --git a/saleor/settings.py b/saleor/settings.py
index 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')