Skip to content

Commit d244678

Browse files
committed
connexion 3
1 parent 7161bce commit d244678

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

main.py

+13-11
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import logging
55
import logging.handlers
66
import connexion
7-
8-
from flask_cors import CORS
7+
from connexion.middleware import MiddlewarePosition
8+
from starlette.middleware.cors import CORSMiddleware
99

1010
# Logging configuration
1111
logger = logging.getLogger()
@@ -15,19 +15,21 @@
1515

1616
# Serve a custom version of the swagger ui (Jinja2 templates) based on the default one
1717
# from the folder 'swagger-ui'. Clone the 'swagger-ui' repository inside the backend folder
18-
options = {"swagger_ui": False}
19-
connexionApp = connexion.App(__name__, options=options)
2018

21-
# Connexion wraps FlaskApp, so app becomes connexionApp.app
22-
app = connexionApp.app
23-
# Access-Control-Allow-Origin
24-
CORS(app)
25-
app.debug = False
19+
app = connexion.App(__name__)
20+
app.add_middleware(
21+
CORSMiddleware,
22+
position=MiddlewarePosition.BEFORE_EXCEPTION,
23+
allow_origins=["*"],
24+
allow_credentials=True,
25+
allow_methods=["*"],
26+
allow_headers=["*"],
27+
)
2628

2729
## New API and web application
2830

2931
# API v1 is defined in v1.yml and its methods are in api.py
30-
connexionApp.add_api('v1.yml')
32+
app.add_api('v1.yml')
3133

3234
if __name__ == "__main__":
33-
app.run(host="0.0.0.0", port=9090, debug=True, use_reloader=False, threaded=True)
35+
app.run(host="0.0.0.0", port=9090)

0 commit comments

Comments
 (0)