Skip to content

Commit

Permalink
fix case when cors are None
Browse files Browse the repository at this point in the history
  • Loading branch information
wochinge committed Oct 8, 2019
1 parent 7127a50 commit 86f3640
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Expand Up @@ -20,6 +20,8 @@ Fixed
- Fixed error ``Object of type 'MaxHistoryTrackerFeaturizer' is not JSON serializable``
when running ``rasa train core``
- Default channel ``send_`` methods no longer support kwargs as they caused issues in incompatible channels
- Fixed ``argument of type 'NoneType' is not iterable`` when using ``rasa shell``,
``rasa interactive`` / ``rasa run``

[1.3.7] - 2019-09-27
^^^^^^^^^^^^^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion rasa/core/agent.py
Expand Up @@ -691,7 +691,7 @@ def handle_channels(
channels: List[InputChannel],
http_port: int = constants.DEFAULT_SERVER_PORT,
route: Text = "/webhooks/",
cors=None,
cors: Union[Text, List[Text], None] = None,
) -> Sanic:
"""Start a webserver attaching the input channels and handling msgs."""

Expand Down
2 changes: 1 addition & 1 deletion rasa/core/run.py
Expand Up @@ -77,7 +77,7 @@ def _create_app_without_api(cors: Optional[Union[Text, List[Text]]] = None):

def configure_app(
input_channels: Optional[List["InputChannel"]] = None,
cors: Optional[Union[Text, List[Text]]] = None,
cors: Optional[Union[Text, List[Text], None]] = None,
auth_token: Optional[Text] = None,
enable_api: bool = True,
jwt_secret: Optional[Text] = None,
Expand Down
10 changes: 7 additions & 3 deletions rasa/server.py
Expand Up @@ -320,15 +320,19 @@ async def _load_agent(
return loaded_agent


def configure_cors(app: Sanic, cors_origins: Union[Text, List[Text]] = "") -> None:
def configure_cors(
app: Sanic, cors_origins: Union[Text, List[Text], None] = ""
) -> None:
"""Configure CORS origins for the given app."""

# Workaround so that socketio works with requests from other origins.
# https://github.com/miguelgrinberg/python-socketio/issues/205#issuecomment-493769183
app.config.CORS_AUTOMATIC_OPTIONS = True
app.config.CORS_SUPPORTS_CREDENTIALS = True

CORS(app, resources={r"/*": {"origins": cors_origins}}, automatic_options=True)
CORS(
app, resources={r"/*": {"origins": cors_origins or ""}}, automatic_options=True
)


def add_root_route(app: Sanic):
Expand All @@ -340,7 +344,7 @@ async def hello(request: Request):

def create_app(
agent: Optional["Agent"] = None,
cors_origins: Union[Text, List[Text]] = "*",
cors_origins: Union[Text, List[Text], None] = "*",
auth_token: Optional[Text] = None,
jwt_secret: Optional[Text] = None,
jwt_method: Text = "HS256",
Expand Down

0 comments on commit 86f3640

Please sign in to comment.