-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
Cors support #493
Conversation
@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? |
rasa_nlu/server.py
Outdated
@@ -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) |
There was a problem hiding this comment.
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).
This is great! Please also add a default value in |
@amn41 Do you want it default to |
I would rather like having the possibility to specify the allowed origin instead of using a wildcard. |
@PHLF I agree and it adds an important level of flexibility and security. I will directly use your I will update the PR in some minutes. |
Awesome! 👍 |
There was a problem hiding this 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: |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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": [], |
There was a problem hiding this comment.
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)
also please add the feature to the documentation so people can use it :)
|
Proposed changes:
Status: