Skip to content

Commit

Permalink
fix(CORS): Include the files/up & files/dl to the cors exempted urls
Browse files Browse the repository at this point in the history
  • Loading branch information
qgerome committed Oct 21, 2024
1 parent 7a506fe commit c210b40
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 5 deletions.
2 changes: 1 addition & 1 deletion config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
if "CORS_ALLOWED_ORIGINS" in os.environ:
CORS_ALLOWED_ORIGINS += os.environ.get("CORS_ALLOWED_ORIGINS").split(",")

CORS_URLS_REGEX = r"^/graphql/(\w+/)?|^/analytics/track/$"
CORS_URLS_REGEX = r"^/graphql/(\w+/)?|^/analytics/track/|^/files/[\w/]+/?$"
CORS_ALLOW_CREDENTIALS = True

CORS_ALLOW_HEADERS = list(default_headers) + [
Expand Down
2 changes: 1 addition & 1 deletion hexa/files/backends/fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ def generate_upload_url(
)
internal_url = reverse("files:upload_file", args=(token,))
if host is None:
host = settings.NEW_FRONTEND_DOMAIN
host = settings.BASE_URL

return f"{host}{internal_url}"

Expand Down
4 changes: 1 addition & 3 deletions hexa/files/tests/backends/test_fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from unittest.mock import patch

from django.core.files.uploadedfile import SimpleUploadedFile
from django.test import override_settings

from hexa.core.test import TestCase
from hexa.files.backends.fs import FileSystemStorage
Expand Down Expand Up @@ -178,13 +177,12 @@ def test_list_bucket_objects_with_prefix_and_query(self):
self.assertEqual(len(res.items), 1)
self.assertEqual(res.items[0].name, "found-2.txt")

@override_settings(NEW_FRONTEND_DOMAIN="http://localhost")
def test_generate_upload_url(self):
self.storage.create_bucket("default-bucket")
url = self.storage.generate_upload_url(
"default-bucket", "file.txt", content_type="text/plain"
)
self.assertTrue(url.startswith("http://localhost/files/up/"))
self.assertTrue(url.startswith("http://localhost:8000/files/up/"))
token = url.split("/")[-2]

self.assertEqual(
Expand Down

0 comments on commit c210b40

Please sign in to comment.