diff --git a/Makefile.local b/Makefile.local --- a/Makefile.local +++ b/Makefile.local @@ -16,7 +16,7 @@ .PHONY: run-wsgi run-wsgi: - export SWH_CONFIG_FILENAME=config/staging.yml; gunicorn --workers=2 'swh.graphql.server:make_app_from_configfile()' + export SWH_CONFIG_FILENAME=config/staging.yml; gunicorn 'swh.graphql.server:make_app_from_configfile()' -w 2 -k uvicorn.workers.UvicornWorker .PHONY: run-dev-docker run-dev-docker: diff --git a/config/staging.yml b/config/staging.yml --- a/config/staging.yml +++ b/config/staging.yml @@ -8,4 +8,4 @@ debug: no -server-type: wsgi +server-type: asgi diff --git a/docker-compose-staging.yml b/docker-compose-staging.yml --- a/docker-compose-staging.yml +++ b/docker-compose-staging.yml @@ -5,4 +5,4 @@ dns: 192.168.100.29 environment: - SWH_CONFIG_FILENAME=config/staging.yml - command: gunicorn --bind=0.0.0.0:8000 --workers=2 'swh.graphql.server:make_app_from_configfile()' + command: gunicorn --bind=0.0.0.0:8000 -w 2 -k uvicorn.workers.UvicornWorker 'swh.graphql.server:make_app_from_configfile()' diff --git a/swh/graphql/server.py b/swh/graphql/server.py --- a/swh/graphql/server.py +++ b/swh/graphql/server.py @@ -62,6 +62,8 @@ SWH_CONFIG_FILENAME environment variable defines the configuration path to load. """ + from starlette.middleware.cors import CORSMiddleware + from .app import schema from .errors.handlers import format_error @@ -74,18 +76,11 @@ server_type = graphql_cfg.get("server-type") if server_type == "asgi": from ariadne.asgi import GraphQL - from starlette.middleware.cors import CORSMiddleware - # Enable cors in the asgi version application = CORSMiddleware( GraphQL(schema, debug=graphql_cfg["debug"], error_formatter=format_error), + # FIXME, restrict origins after deploying the JS client allow_origins=["*"], allow_methods=("GET", "POST", "OPTIONS"), ) - else: - from ariadne.wsgi import GraphQL - - application = GraphQL( - schema, debug=graphql_cfg["debug"], error_formatter=format_error - ) return application