diff --git a/.idea/announcementService.iml b/.idea/announcementService.iml index 78e851b..1656a67 100644 --- a/.idea/announcementService.iml +++ b/.idea/announcementService.iml @@ -11,6 +11,9 @@ + + + diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml index 1bc33e4..7780e89 100644 --- a/.idea/dataSources.xml +++ b/.idea/dataSources.xml @@ -2,7 +2,7 @@ - mongo + mongo.4 true com.dbschema.MongoJdbcDriver mongodb://localhost:27017 diff --git a/app.py b/app.py index 841a357..1aebc0c 100644 --- a/app.py +++ b/app.py @@ -1,4 +1,5 @@ from flask import Flask, jsonify, request +from flask_cors import cross_origin app = Flask(__name__) diff --git a/gen/openapi_server/__main__.py b/gen/openapi_server/__main__.py index 67e257f..963bcdc 100644 --- a/gen/openapi_server/__main__.py +++ b/gen/openapi_server/__main__.py @@ -2,21 +2,33 @@ import logging import connexion +from connexion.middleware import MiddlewarePosition +from flask import Flask from openapi_server import encoder from pymongo import MongoClient +from starlette.middleware.cors import CORSMiddleware + client = MongoClient(host='mongodb://host.docker.internal:27017/') db = client["MainDB"] collection = db['patch_notes'] -app = connexion.App(__name__, specification_dir='./openapi/') -app.app.logger.setLevel(logging.DEBUG) -app.app.json_encoder = encoder.JSONEncoder +app = connexion.FlaskApp(__name__, specification_dir='./openapi/') + +app.add_middleware( + CORSMiddleware, + position=MiddlewarePosition.BEFORE_EXCEPTION, + allow_origins=["*"], + allow_credentials=True, + allow_methods=["*"], + allow_headers=["*"], +) + app.add_api('openapi.yaml', base_path='/api', arguments={'title': 'announcementService'}, pythonic_params=True) if __name__ == '__main__': - app.run(port=8080, host='0.0.0.0') \ No newline at end of file + app.run(port=8080, host='0.0.0.0') diff --git a/gen/openapi_server/controllers/patchnotes_controller.py b/gen/openapi_server/controllers/patchnotes_controller.py index 9c7850e..178b50b 100644 --- a/gen/openapi_server/controllers/patchnotes_controller.py +++ b/gen/openapi_server/controllers/patchnotes_controller.py @@ -213,3 +213,12 @@ def patchnotes_get(): # noqa: E501 mimetype='application/json', status=200, ) + +def cors_options_handler(): + from flask import make_response + response = make_response('') + response.headers['Access-Control-Allow-Origin'] = '*' + response.headers['Access-Control-Allow-Methods'] = 'GET, POST, PUT, DELETE, OPTIONS' + response.headers['Access-Control-Allow-Headers'] = 'Content-Type, Authorization' + return response + diff --git a/gen/requirements.txt b/gen/requirements.txt index f7e57e3..7685c5c 100644 --- a/gen/requirements.txt +++ b/gen/requirements.txt @@ -10,4 +10,5 @@ connexion[swagger-ui, flask] >= 3.2.0 werkzeug == 3.1.3 swagger-ui-bundle >= 0.0.2 uvicorn >= 0.21.1 -typing_extensions~=4.12.2 \ No newline at end of file +typing_extensions~=4.12.2 +flask_cors >= 5.0.1 \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index f7e57e3..29a18e6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,4 +10,8 @@ connexion[swagger-ui, flask] >= 3.2.0 werkzeug == 3.1.3 swagger-ui-bundle >= 0.0.2 uvicorn >= 0.21.1 -typing_extensions~=4.12.2 \ No newline at end of file +typing_extensions~=4.12.2 +flask_cors >= 5.0.1 +typing_extensions==4.12.2 +Flask-Testing==0.8.1 +starlette==0.46.1 \ No newline at end of file