Skip to content

Commit

Permalink
Add CORS support (#478)
Browse files Browse the repository at this point in the history
* Add optional CORS

* make CORS an extra dependency

* add documentation
  • Loading branch information
itajaja authored and mistercrunch committed Jun 2, 2016
1 parent c78d368 commit 5f005d6
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
4 changes: 4 additions & 0 deletions caravel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
backupCount=app.config.get('BACKUP_COUNT'))
logging.getLogger().addHandler(handler)

if app.config.get('ENABLE_CORS'):
from flask.ext.cors import CORS
CORS(app, **app.config.get('CORS_OPTIONS'))


class MyIndexView(IndexView):
@expose('/')
Expand Down
4 changes: 4 additions & 0 deletions caravel/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@
CACHE_DEFAULT_TIMEOUT = None
CACHE_CONFIG = {'CACHE_TYPE': 'null'}

# CORS Options
ENABLE_CORS = False
CORS_OPTIONS = {}


# ---------------------------------------------------
# List of viz_types not allowed in your environment
Expand Down
16 changes: 15 additions & 1 deletion docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ the required dependencies are installed: ::

For **Fedora** and **RHEL-derivatives**, the following command will ensure
that the required dependencies are installed: ::

sudo yum upgrade python-setuptools
sudo yum install gcc libffi-devel python-devel python-pip python-wheel openssl-devel

Expand Down Expand Up @@ -228,6 +228,20 @@ Note that you can run the ``caravel refresh_druid`` command to refresh the
metadata from your Druid cluster(s)


CORS
-----

The extra CORS Dependency must be installed:

caravel[cors]


The following keys in `caravel_config.py` can be specified to configure CORS:


* ``ENABLE_CORS``: Must be set to True in order to enable CORS
* ``CORS_OPTIONS``: options passed to Flask-CORS (`documentation <http://flask-cors.corydolphin.com/en/latest/api.html#extension>`)

Upgrading
---------

Expand Down
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
'sqlparse>=0.1.16, <0.2.0',
'werkzeug>=0.11.2, <0.12.0',
],
extras_require={
'cors': ['Flask-Cors>=2.0.0'],
},
tests_require=['coverage'],
author='Maxime Beauchemin',
author_email='maximebeauchemin@gmail.com',
Expand Down

0 comments on commit 5f005d6

Please sign in to comment.