Skip to content
Discussion options

You must be logged in to vote

Sorry to necrobump, but I think I know what the OP intended to do.

I think the important part of the documentation is CORS preflight requests, which mentions that "These are any OPTIONS request with Origin and Access-Control-Request-Method headers".

In other words, Starlette and FastAPI will only reply successfully to an OPTIONS request if both headers are present.

For example, let's take the first steps server and add a CORS middleware to it:

from fastapi import FastAPI
from starlette.middleware import Middleware
from starlette.middleware.cors import CORSMiddleware

app = FastAPI(middleware=[
    Middleware(CORSMiddleware, allow_origins=["*"])
])

@app.get("/")
async def root():
    return

Replies: 5 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by Kludex
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question or problem question-migrate
4 participants
Converted from issue

This discussion was converted from issue #1849 on February 28, 2023 01:14.