You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Oct 2, 2018. It is now read-only.
great solution! Thanks. However, the middleware does not send headers when serving static files - this would be ok for Apache via WSGI since it can be achieved by mod_headers. But for local testing it would be great, if django-cors middleware would also add headers to files served by staticfiles. Is there a chance to do this?
thanks a lot!
Andy
The text was updated successfully, but these errors were encountered:
I wrote a quick patch for django core, which hooks in django-cors - this is not a final solution, however, it saved me the night ;-)
Maybe it helps to understand what I mean. Because static files are not served via the middleware pipeline, no CORS headers will be set for images, CSS, and most importantly JS files!
Best,
Andy
--- ../bigdatamaps_server/venv/lib/python2.7/site-packages/django/views/static.py 2012-09-26 23:59:13.000000000 +0200+++ venv/lib/python2.7/site-packages/django/views/static.py 2012-10-13 18:37:16.000000000 +0200@@ -62,6 +62,12 @@
with open(fullpath, 'rb') as f:
response = HttpResponse(f.read(), mimetype=mimetype)
response["Last-Modified"] = http_date(statobj.st_mtime)
++ # cors middleware hook+ from cors.middleware import AllowOriginMiddleware+ cmw = AllowOriginMiddleware()+ cmw.process_response(request, response)+
if stat.S_ISREG(statobj.st_mode):
response["Content-Length"] = statobj.st_size
if encoding:
if you want to get an executable patch (github applied formatting rules), just drop me a message
(I fiddled with your comment to pretty the diff snippet.)
Thanks for the explanation about static files not going through middleware. I didn't know that about Django. How to fix that is a good question. I'll have to think about that a bit.
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Hi,
great solution! Thanks. However, the middleware does not send headers when serving static files - this would be ok for Apache via WSGI since it can be achieved by mod_headers. But for local testing it would be great, if django-cors middleware would also add headers to files served by staticfiles. Is there a chance to do this?
thanks a lot!
Andy
The text was updated successfully, but these errors were encountered: