Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cors support #493

Merged
merged 7 commits into from
Jul 21, 2017
Merged

Cors support #493

merged 7 commits into from
Jul 21, 2017

Conversation

skreutzberger
Copy link
Contributor

@skreutzberger skreutzberger commented Jul 20, 2017

Proposed changes:

Status:

  • ready for code review
  • there are tests for the functionality
  • documentation updated
  • changelog updated

@wrathagom
Copy link
Contributor

@tmbo do I read the Travis stuff correct that this looks like it's just a timeout of some sorts. Can you manually kick off the tests again?

@@ -58,6 +59,8 @@ def decorated(*args, **kwargs):

def create_app(config, component_builder=None):
rasa_nlu_app = Flask(__name__)
if 'cors' in config and config['cors'] == True:
CORS(rasa_nlu_app)
Copy link
Contributor

@PHLF PHLF Jul 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about how to achieve it, but would it be possible to use CORS(app, resources={r"/*": {"origins": config['cors_origin']}}) instead?
With cors being a configuration setting accepting either a string or a list of URIs (strings).

@amn41
Copy link
Contributor

amn41 commented Jul 20, 2017

This is great! Please also add a default value in rasa_nlu/config.py , see here

@skreutzberger
Copy link
Contributor Author

@amn41 Do you want it default to True or False?

@PHLF
Copy link
Contributor

PHLF commented Jul 20, 2017

I would rather like having the possibility to specify the allowed origin instead of using a wildcard.

@skreutzberger
Copy link
Contributor Author

@PHLF I agree and it adds an important level of flexibility and security. I will directly use your cors_origins example. As default value I will forbid it (by using an empty list). For wildcard you can then still use ['*'] or go more restricted with ['*.mydomain.com', 'foo.bar.com']

I will update the PR in some minutes.

@PHLF
Copy link
Contributor

PHLF commented Jul 21, 2017

Awesome! 👍

Copy link
Member

@tmbo tmbo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! couple of minor changes and we are ready to merge 👍

@@ -58,6 +59,8 @@ def decorated(*args, **kwargs):

def create_app(config, component_builder=None):
rasa_nlu_app = Flask(__name__)
if 'cors_origins' in config:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for the check, it will always be set (configuration is initialized with the defaults, so the key is always present)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am always doing that to avoid errors in the future. I am careful in expecting keys in a dict in all programming languages.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right - and that is probably a good habit. There is a reason though we don't do it for the configuration values (and the reason why the configuration isn't simply a dict but a separate class): it ensures that every configuration key we expect to be present is present and set to a default value. This keeps all the default values in one place and avoids the need to handle unset values at every point the configuration is accessed.

requirements.txt Outdated
@@ -1,6 +1,7 @@
-e .
gevent==1.2.1
flask==0.12
flask-cors
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs to be pinned to a version

@@ -30,6 +30,7 @@
"port": 5000,
"server_model_dirs": None,
"token": None,
"cors_origins": [],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs to be added to config_defaults.json as well (this will also fix the failing test)

@tmbo
Copy link
Member

tmbo commented Jul 21, 2017

also please add the feature to the documentation so people can use it :)

@tmbo tmbo merged commit b839514 into RasaHQ:master Jul 21, 2017
@skreutzberger skreutzberger deleted the cors-support branch July 24, 2017 05:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants