Skip to content

Commit

Permalink
fix cors issue
Browse files Browse the repository at this point in the history
  • Loading branch information
jdkent committed Nov 3, 2023
1 parent cd943a0 commit e155dd1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
16 changes: 13 additions & 3 deletions store/neurostore/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
from pathlib import Path
from werkzeug.middleware.profiler import ProfilerMiddleware

from connexion.middleware import MiddlewarePosition
from starlette.middleware.cors import CORSMiddleware
from authlib.integrations.flask_client import OAuth
import connexion
# from connexion.json_schema import default_handlers as json_schema_handlers
from connexion.resolver import MethodResolver
from flask_caching import Cache
from flask_cors import CORS
import sqltap.wsgi

from .or_json import ORJSONDecoder, ORJSONEncoder
Expand Down Expand Up @@ -35,6 +36,16 @@

openapi_file = Path(os.path.dirname(__file__) + "/openapi/neurostore-openapi.yml")

# Enable CORS
connexion_app.add_middleware(
CORSMiddleware,
position=MiddlewarePosition.BEFORE_ROUTING,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)

connexion_app.add_api(
openapi_file,
base_path="/api",
Expand All @@ -45,8 +56,7 @@
validate_responses=os.getenv("DEBUG", False) == "True",
)

# Enable CORS
cors = CORS(app)


auth0 = oauth.register(
"auth0",
Expand Down
3 changes: 1 addition & 2 deletions store/neurostore/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
aniso8601~=8.1
auth0-python~=3.16
authlib~=0.15
connexion[swagger-ui,uvicorn,flask]==3.0.0a7
connexion[swagger-ui,uvicorn,flask]==3.0.0
email-validator~=1.1
flake8~=3.8
flask~=2.0
flask-caching~=2.0
flask-cors~=3.0
flask-dance~=3.2
flask-shell-ipython~=0.4
flask-migrate~=2.5
Expand Down
5 changes: 5 additions & 0 deletions store/neurostore/tests/api/test_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ def test_read(auth_client, user_data, endpoint, model, schema, session):

expected_results = model.query.filter(query).all()

pre = auth_client.client.options(
f"/api/{endpoint}",
headers={'Origin': 'http://example.com', 'Access-Control-Request-Method': 'GET'}
)
assert pre.status_code == 200
resp = auth_client.get(f"/api/{endpoint}/")

assert resp.status_code == 200
Expand Down

0 comments on commit e155dd1

Please sign in to comment.