Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VersionedFastAPI causes all OPTIONS requests to return a 405 #23

Open
RA-Zagros opened this issue Nov 24, 2020 · 1 comment
Open

VersionedFastAPI causes all OPTIONS requests to return a 405 #23

RA-Zagros opened this issue Nov 24, 2020 · 1 comment

Comments

@RA-Zagros
Copy link

Describe the bug
When using VersionedFastAPI all OPTIONS requests return a 405.

app = FastAPI(title='APP NAME')
APP_VERSION = "1.1.1"
app.add_middleware(
    CORSMiddleware,
    allow_origin_regex='https?://.*',
    allow_credentials=True,
    allow_methods=['*'],
    allow_headers=['*'],
)
app.include_router(api_router_v1_0, prefix=config.API_V1_STR)
app.include_router(api_router_v1_1, prefix=config.API_V1_STR)
app = VersionedFastAPI(app)

To Reproduce
Steps to reproduce the behavior:

  1. initialize app using VersionedFastAPI
  2. make a request that requires CORS options
  3. view response details
  4. returns a 405

Expected behavior
Options request to pass as expected

@sammaphey
Copy link

I had to add the middleware after Declaring the VersionedFastAPI. So this should hopefully fix it:

app = FastAPI(title='APP NAME')
APP_VERSION = "1.1.1"
app.include_router(api_router_v1_0, prefix=config.API_V1_STR)
app.include_router(api_router_v1_1, prefix=config.API_V1_STR)
app = VersionedFastAPI(app)
app.add_middleware(
    CORSMiddleware,
    allow_origin_regex='https?://.*',
    allow_credentials=True,
    allow_methods=['*'],
    allow_headers=['*'],
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants