Hello, everybody!
I am trying to add CORS header to request in middleware, but then I get OPTIONS request
it gets into the handler function, but I won’t it. How can i prevent gets into my handler function request OPTIONS?
Or how can I process a request before a handler?
This example
@app.middleware('response')
async def CORS_middlware(request, response_query):
CORS_HEADERS = {
'Access-Control-Allow-Origin': 'http://127.0.0.1:8081',
'Access-Control-Allow-Credentials': 'true',
'Access-Control-Allow-Methods': 'GET,POST,PUT,DELETE,OPTIONS',
'Access-Control-Allow-Headers': 'Content-Type'
}
if request.method == 'OPTIONS':
resp = response.empty()
resp.headers.update(**CORS_HEADERS)
return resp
response_query.headers.update(**CORS_HEADERS)