final version
This commit is contained in:
@@ -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')
|
||||
app.run(port=8080, host='0.0.0.0')
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user