Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add and use AllowAllCORSMixin #1099

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions django/thunderstore/core/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,12 @@ def get_admin_url(self):

class Meta:
abstract = True


# AllowAllCORSMixin must be inherited before APIView / GenericAPIView
class AllowAllCORSMixin:
def finalize_response(self, request, response, *args, **kwargs):
response = super().finalize_response(request, response, *args, **kwargs)
response["Access-Control-Allow-Origin"] = "*"
response["Access-Control-Allow-Methods"] = "GET"
return response
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from rest_framework.throttling import UserRateThrottle
from rest_framework.views import APIView

from thunderstore.core.mixins import AllowAllCORSMixin
from thunderstore.core.utils import replace_cdn
from thunderstore.modpacks.models import LegacyProfile

Expand Down Expand Up @@ -53,7 +54,7 @@ def post(self, request, *args, **kwargs):
)


class LegacyProfileRetrieveApiView(APIView):
class LegacyProfileRetrieveApiView(AllowAllCORSMixin, APIView):
permission_classes = []

@swagger_auto_schema(
Expand Down
Loading