You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So, I went through documentation and I made this test application, to see if the CORSMiddleware even works. Well, apparently it doesn't work at all, the headers are not being sent and the OPTIONS request still returns 405.
Is it just me misunderstanding something and if so, what exactly? If it's not just me, then I think something is broken here.
I would really appreciate some TIP on that, since I rewrote one of my API wrappers to starlette and it doesn't really work, because of cors ;-;
My application code
from starlette.applications import Starlette
from starlette.responses import JSONResponse, PlainTextResponse
from starlette.middleware import Middleware
from starlette.middleware.cors import CORSMiddleware
from starlette.exceptions import HTTPException
middleware = [
Middleware(CORSMiddleware, allow_origins=['*'], allow_methods=["GET", "OPTIONS"],
allow_headers=["Token", "Origin", "X-Requested-With", "Content-Type", "Accept"])
]
app = Starlette(middleware=middleware)
@app.route('/')
async def homepage(request):
return JSONResponse(content={"message": "hi"})
@app.route('/test')
async def test(request):
return JSONResponse(content={"test": "the test route"})
Here's results of the request to root:
The text was updated successfully, but these errors were encountered:
So, I went through documentation and I made this test application, to see if the CORSMiddleware even works. Well, apparently it doesn't work at all, the headers are not being sent and the OPTIONS request still returns 405.
Is it just me misunderstanding something and if so, what exactly? If it's not just me, then I think something is broken here.
I would really appreciate some TIP on that, since I rewrote one of my API wrappers to starlette and it doesn't really work, because of cors ;-;
My application code
Here's results of the request to root:
The text was updated successfully, but these errors were encountered: