Support cross-origin frontends alongside same-origin setups
- django-cors-headers with env-driven CORS_ALLOWED_ORIGINS, CORS_ALLOW_ALL_ORIGINS, CORS_ALLOW_CREDENTIALS and CSRF_TRUSTED_ORIGINS; same-origin traffic is unaffected and a disallowed origin gets no CORS headers. Token auth needs no cookies, so credentials stay off by default. - TRUST_PROXY_HEADERS=true lets a TLS-terminating proxy supply X-Forwarded-Proto/Host for correct absolute URLs. - API media URLs (raw/thumbnail/upload/similarity/staged previews) are now absolute, built from the request host, so <img>/<video>/fetch() keep working when the SPA is served from another origin. Signed URLs are still per-user; nothing is stored in the DB. - The SPA gains VITE_API_BASE (build-time, empty = same-origin) applied by a small apiUrl() helper used for XHR/fetch and the few URL fallbacks. Verified with a throwaway instance: preflight and GET responses carry the allowed origin, foreign origins get nothing, media GETs include CORS for cross-origin fetch(), and payload URLs use the request host (dev :8000 unchanged).
This commit is contained in:
@@ -119,7 +119,9 @@ class SimilarityCheckViewSet(
|
||||
check.md5 = services.compute_md5(check.file.path)
|
||||
|
||||
exact = MediaItem.objects.filter(md5=check.md5).first()
|
||||
matches = find_library_matches(check.file.path, limit=12, user=request.user)
|
||||
matches = find_library_matches(
|
||||
check.file.path, limit=12, user=request.user, request=request
|
||||
)
|
||||
if exact is not None:
|
||||
exact_j_id = f"J-{exact.id}"
|
||||
matches = [
|
||||
|
||||
Reference in New Issue
Block a user