add cors headers to api
authorymh <ymh.work@gmail.com>
Sun, 15 Feb 2015 00:56:46 +0100
changeset 223 bb1d902e0f63
parent 222 7148746cb47a
child 224 20f848b89d16
add cors headers to api
src/ldtplatform/settings.py
virtualenv/res/lib/lib_create_env.py
virtualenv/res/src/django-cors-headers-1.0.0.tar.gz
virtualenv/web/res/res_create_env.py
--- a/src/ldtplatform/settings.py	Fri Jan 30 15:34:34 2015 +0100
+++ b/src/ldtplatform/settings.py	Sun Feb 15 00:56:46 2015 +0100
@@ -80,6 +80,7 @@
 
 MIDDLEWARE_CLASSES = (
     'django.middleware.cache.UpdateCacheMiddleware',
+    'corsheaders.middleware.CorsMiddleware',
     'django.middleware.common.CommonMiddleware',
     'django.middleware.cache.FetchFromCacheMiddleware',
     'django.middleware.gzip.GZipMiddleware',
@@ -129,6 +130,7 @@
     'django.contrib.admin',
     'django.contrib.staticfiles',
     'haystack',
+    'corsheaders',
     'tastypie',
     'guardian',
     'taggit',
@@ -249,6 +251,9 @@
 }
 HAYSTACK_SIGNAL_PROCESSOR = 'ldt.indexation.signals.LdtSignalProcessor'
 
+#Cors headers for API
+CORS_ORIGIN_ALLOW_ALL = True
+
 from config import *
 
 if not "SRC_BASE_URL" in locals():
@@ -275,6 +280,9 @@
 if not "MEDIA_URL" in locals():
     MEDIA_URL = BASE_URL + 'static/media/'
 
+if not "CORS_URLS_REGEX" in locals():
+    CORS_URLS_REGEX = r"^" + BASE_URL + 'ldtplatform/api/.*$'
+
 #forced settings    
 MAX_TAG_LENGTH = 255
 FORCE_LOWERCASE_TAGS = True
--- a/virtualenv/res/lib/lib_create_env.py	Fri Jan 30 15:34:34 2015 +0100
+++ b/virtualenv/res/lib/lib_create_env.py	Sun Feb 15 00:56:46 2015 +0100
@@ -47,6 +47,7 @@
     'PYTHON-DIGEST' : {'setup':'python-digest', 'url':'http://pypi.python.org/packages/source/p/python-digest/python-digest-1.7.tar.gz', 'local': 'python-digest-1.7.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}},
     'DEFUSEDXML' : {'setup':'defusedxml', 'url':'https://pypi.python.org/packages/source/d/defusedxml/defusedxml-0.4.1.tar.gz', 'local': 'defusedxml-0.4.1.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}},
     'DJANGO-TASTYPIE' : {'setup':'django-tastypie', 'url':'https://github.com/toastdriven/django-tastypie/archive/v0.9.15.tar.gz', 'local': 'django-tastypie-0.9.15.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}},
+    'DJANGO-CORS-HEADERS' : {'setup':'django-cors-headers', 'url':'https://github.com/ottoyiu/django-cors-headers/archive/1.0.0.tar.gz', 'local': 'django-cors-headers-1.0.0.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}},
     'DJANGO-CHUNCKED-UPLOADS' : {'setup': 'django-chuncked-uploads', 'url':'https://github.com/IRI-Research/django-chunked-uploads/archive/v0.5.tar.gz', 'local':'django-chunked-uploads-0.5.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}},
 }
 
Binary file virtualenv/res/src/django-cors-headers-1.0.0.tar.gz has changed
--- a/virtualenv/web/res/res_create_env.py	Fri Jan 30 15:34:34 2015 +0100
+++ b/virtualenv/web/res/res_create_env.py	Sun Feb 15 00:56:46 2015 +0100
@@ -37,6 +37,7 @@
     'PYTHON-DIGEST',
     'DEFUSEDXML',
     'DJANGO-TASTYPIE',
+    'DJANGO-CORS-HEADERS',
     'DJANGO-CHUNCKED-UPLOADS',
 ]